100% found this document useful (1 vote)
12 views

Pro Python System Administration 2nd Edition Rytis Sileika download

The document provides information about the book 'Pro Python System Administration 2nd Edition' by Rytis Sileika, which focuses on using Python for various system administration tasks. It covers topics such as network management, web server management, database management, and system monitoring, with practical examples and applications. The book is structured into 14 chapters, each addressing specific problems and solutions related to system administration using Python.

Uploaded by

dumorakimika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
12 views

Pro Python System Administration 2nd Edition Rytis Sileika download

The document provides information about the book 'Pro Python System Administration 2nd Edition' by Rytis Sileika, which focuses on using Python for various system administration tasks. It covers topics such as network management, web server management, database management, and system monitoring, with practical examples and applications. The book is structured into 14 chapters, each addressing specific problems and solutions related to system administration using Python.

Uploaded by

dumorakimika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

Pro Python System Administration 2nd Edition

Rytis Sileika pdf download

https://ebookfinal.com/download/pro-python-system-
administration-2nd-edition-rytis-sileika/

Explore and download more ebooks or textbooks


at ebookfinal.com
We have selected some products that you may be interested in
Click the link to download now or visit ebookfinal.com
for more options!.

Automating Linux and Unix System Administration 2nd


Edition Nathan Campi

https://ebookfinal.com/download/automating-linux-and-unix-system-
administration-2nd-edition-nathan-campi/

Principles of Network and System Administration 2nd ed


Edition Mark Burgess

https://ebookfinal.com/download/principles-of-network-and-system-
administration-2nd-ed-edition-mark-burgess/

Mastering Linux System Administration 1st Edition


Christine Bresnahan

https://ebookfinal.com/download/mastering-linux-system-
administration-1st-edition-christine-bresnahan/

UNIX and Linux System Administration Handbook Fourth


Edition Evi Nemeth

https://ebookfinal.com/download/unix-and-linux-system-administration-
handbook-fourth-edition-evi-nemeth/
LDAP System Administration Putting Directories to Work 1st
Edition Carter

https://ebookfinal.com/download/ldap-system-administration-putting-
directories-to-work-1st-edition-carter/

Pro Exchange Administration Understanding On premises and


Hybrid Exchange Deployments Third Edition Jaap Wesselius

https://ebookfinal.com/download/pro-exchange-administration-
understanding-on-premises-and-hybrid-exchange-deployments-third-
edition-jaap-wesselius/

Automating System Administration with Perl Tools to Make


You More Efficient 2nd ed Edition David N Blank-Edelman

https://ebookfinal.com/download/automating-system-administration-with-
perl-tools-to-make-you-more-efficient-2nd-ed-edition-david-n-blank-
edelman/

Pro Puppet 2nd Edition Spencer Krum

https://ebookfinal.com/download/pro-puppet-2nd-edition-spencer-krum/

Python in easy steps Covers Python 3 7 2nd Edition Mike


Mcgrath

https://ebookfinal.com/download/python-in-easy-steps-covers-
python-3-7-2nd-edition-mike-mcgrath/
Pro Python System Administration 2nd Edition Rytis
Sileika Digital Instant Download
Author(s): Rytis Sileika
ISBN(s): 9781484202180, 148420218X
File Details: PDF, 5.48 MB
Year: 2014
Language: english
www.it-ebooks.info
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.

www.it-ebooks.info
Contents at a Glance

About the Author�������������������������������������������������������������������������������������������������������������� xvii


About the Technical Reviewers����������������������������������������������������������������������������������������� xix
Acknowledgments������������������������������������������������������������������������������������������������������������� xxi
Introduction��������������������������������������������������������������������������������������������������������������������� xxiii

■■Chapter 1: Reading and Collecting Performance Data Using SNMP����������������������������������1


■■Chapter 2: Managing Devices Using the SOAP API����������������������������������������������������������37
■■Chapter 3: Creating a Web Application for IP Address Accountancy������������������������������79
■■Chapter 4: Integrating the IP Address Application with DHCP��������������������������������������111
■■Chapter 5: Maintaining a List of Virtual Hosts in an Apache Configuration File������������143
■■Chapter 6: Gathering and Presenting Statistical Data from Apache Log Files��������������163
■■Chapter 7: Performing Complex Searches and Reporting on Application Log Files������189
■■Chapter 8: A Website Availability Check Script for Nagios��������������������������������������������217
■■Chapter 9: Management and Monitoring Subsystem����������������������������������������������������241
■■Chapter 10: Remote Monitoring Agents������������������������������������������������������������������������275
■■Chapter 11: Statistics Gathering and Reporting������������������������������������������������������������301
■■Chapter 12: Distributed Message Processing System���������������������������������������������������331
■■Chapter 13: Automatic MySQL Database Performance Tuning��������������������������������������349
■■Chapter 14: Using Amazon EC2/S3 as a Data Warehouse Solution�������������������������������367

Index���������������������������������������������������������������������������������������������������������������������������������391

www.it-ebooks.info
Introduction

The role of the system administrator has grown dramatically over the years. The number of systems supported
by a single engineer has also increased. As such, it is impractical to handcraft each installation, and there is a
need to automate as many tasks as possible. The structure of systems varies from organization to organization,
therefore system administrators must be able to create their own management tools. Historically, the most popular
programming languages for these tasks were UNIX shell and Perl. They served their purposes well, and I doubt they
will ever cease to exist. However, the complexity of current systems requires new tools, and the Python programming
language is one of them.
Python is an object-oriented programming language suitable for developing large-scale applications. Its syntax
and structure make it very easy to read—so much so that the language is sometimes referred to as “executable
pseudocode.” The Python interpreter allows for interactive execution, so in some situations an administrator can use
it instead of a standard UNIX shell. Although Python is primarily an object-oriented language, it is easily adopted
for procedural and functional styles of programming. Given all that, Python makes a perfect fit as a new language for
implementing system administration applications. There are a large number of Linux system utilities already written
in Python, such as the Yum package manager and Anaconda, the Linux installation program.

The Prerequisites for Using this Book


This book is about using the Python programming language to solve specific system administration tasks. We look at
the four distinctive system administration areas: network management, web server and web application management,
database system management, and system monitoring. Although I explain in detail most of the technologies used in
this book, bear in mind that the main goal here is to display the practical application of the Python libraries so as to
solve rather specific issues. Therefore, I assume that you are a seasoned system administrator. You should be able to
find additional information yourself; this book gives you a rough guide for how to reach your goal, but you must be
able to work out how to adapt it to your specific system and environment.
As we discuss the examples, you will be asked to install additional packages and libraries. In most cases, I provide
the commands and instructions to perform these tasks on a Fedora system, but you should be ready to adopt the
instructions to the Linux distribution that you are going to use. Most of the examples also work without many
modification on a recent OS X release (10.10.X).
I also assume that you have a background in the Python programming language. I introduce the specific
libraries that are used in system administration tasks, as well as some lesser known or less often discussed language
functionality, such as the generator functions or the class internal methods, but the basic language syntax is
not explained here. If you want to refresh your Python skills, I recommend the following books: Pro Python by
Marty Alchin and J. Burton Browning (Apress, 2012; but watch for a new edition due to be released in early 2015);
Python Programming for the Absolute Beginner by Mike Dawson (Course Technology PTR, 2010); and Core Python
Applications Programming by Wesley Chun (Prentice Hall, 2012)
All examples presented in this book assume the Python version 2.7. This is mostly dictated by the libraries that
are used in the examples. Some libraries have been ported to Python 3; however, some have not. So if you need to run
Python 3, make sure you check that the required libraries have Python 3 support.

xxiii

www.it-ebooks.info
■ Introduction

The Structure of this Book


This book contains 14 chapters, and each chapter solves a distinctive problem. Some examples span multiple
chapters, but even then, each chapter deals with a specific aspect of the particular problem.
In addition to the chapters, several other organizational layers characterize this book. First, I grouped the
chapters by the problem type. Chapters 1 to 4 deal with network management issues; Chapters 5 to 7 talk about the
Apache web server and web application management; Chapters 8 to 11 are dedicated to monitoring and statistical
calculations; and Chapters 12 and 13 focus on database management issues.
Second, I maintain a common pattern in all chapters. I start with the problem statement and then move on to
gather requirements and proceed through the design phase before moving into the implementation section.
Third, each chapter focuses on one or more technologies and the Python libraries that provide the language
interface for the particular technology. Examples of such technologies could be the SOAP protocol, application
plug-in architecture, or cloud computing concepts.
More specifically, here’s a breakdown of the chapters:
Chapter 1: Reading and Collecting Performance Data Using SNMP
Most network-attached devices expose the internal counters via the Simple Network Management Protocol (SNMP).
This chapter explains basic SNMP principles and the data structure. We then look at the Python libraries that provide
the interface to SNMP–enabled devices. We also investigate the round robin database, which is the de facto standard
for storing the statistical data. Finally, we look at the Jinja2 template framework, which allows us to generate simple
web pages.
Chapter 2: Managing Devices Using the SOAP API
Complicated tasks, such as managing the device configuration, cannot be easily done by using SNMP because
the protocol is too simplistic. Therefore, advanced devices, such as the Citrix Netscaler load balancers, provide the
SOAP API interface to the device management system. In this chapter, we investigate the SOAP API structure and the
libraries that enable the SOAP–based communication from the Python programming language. We also look at the
basic logging functionality using the built-in libraries. This second edition of the book includes examples of how to
use the new REST API to manage the load balancer devices.
Chapter 3: Creating a Web Application for IP Address Accountancy
In this chapter, we build a web application that maintains the list of the assigned IP addresses and the address
ranges. We learn how to create web applications using the Django framework. I show you the way the Django
application should be structured, tell how to create and configure the application settings, and explain the URL
structure. We also investigate how to deploy the Django application using the Apache web server.
Chapter 4: Integrating the IP Address Application with DHCP
This chapter expands on the previous chapter, and we implement the DHCP address range support. We also look
at some advanced Django programming techniques, such as customizing the response MIME type and serving AJAX
calls. This second edition adds new functionality to manage dynamic DHCP leases using OMAPI protocol.
Chapter 5: Maintaining a List of Virtual Hosts in an Apache Configuration File
This is another Django application that we develop in this book, but this time our focus is on the Django
administration interface. While building the Apache configuration management application, you learn how to
customize the default Django administration interface with your own views and functions.

xxiv

www.it-ebooks.info
■ Introduction

Chapter 6: Gathering and Presenting Statistical Data from Apache Log Files
In this chapter, the goal is to build an application that parses and analyses the Apache web server log files.
Instead of taking the straightforward but inflexible approach of building a monolithic application, we look at the
design principles involved in building plug-in applications. You learn how to use the object and class type discovery
functions and how to perform a dynamic module loading. This second edition of the book shows you how to perform
data visualization based on the gathered data.
Chapter 7: Performing Complex Searches and Reporting on Application Log Files
This chapter also deals with the log file parsing, but this time I show you how to parse complex, multi-line log
file entries. We investigate the functionality of the open-source log file parser tool called Exctractor, which you can
download from http://exctractor.sourceforge.net/.
Chapter 8: A Web Site Availability Check Script for Nagios
Nagios is one of the most popular open-source monitoring systems, because its modular structure allows users
to implement their own check scripts and thus customize the tool to meet their needs. In this chapter, we create two
scripts that check the functionality of a website. We investigate how to use the Beautiful Soup HTML parsing library to
extract the information from the HTML web pages.
Chapter 9: Management and Monitoring Subsystem
This chapter starts a three-chapter series in which we build a complete monitoring system. The goal of this
chapter is not to replace mature monitoring systems such as Nagios or Zenoss but to show the basic principles of the
distributed application programming. We look at database design principles such as data normalization. We also
investigate how to implement the communication mechanisms between network services using the RPC calls.
Chapter 10: Remote Monitoring Agents
This is the second chapter in the monitoring series, where we implement the remote monitoring agent
components. In this chapter, I also describe how to decouple the application from its configuration using the
ConfigParser module.
Chapter 11: Statistics Gathering and Reporting
This is the last part of the monitoring series, where I show you how to perform basic statistical analysis on the
collected performance data. We use scientific libraries: NumPy to perform the calculations and matplotlib to create
the graphs. You learn how to find which performance readings fall into the comfort zone and how to calculate the
boundaries of that zone. We also do the basic trend detection, which provides a good insight for the capacity planning.
Chapter 12: Distributed Message Processing System
This is a new chapter for the second edition of the book. In this chapter I show you how to convert the distributed
management system to use Celery, a remote task execution framework.
Chapter 13: Automatic MySQL Database Performance Tuning
In this chapter, I show you how to obtain the MySQL database configuration variables and the internal status
indicators. We build an application that makes a suggestion on how to improve the database engine performance
based on the obtained data.
Chapter 14: Amazon EC2/S3 as a Data Warehouse Solution
This chapter shows you how to utilize the Amazon Elastic Compute Cloud (EC2) and offload the infrequent
computation tasks to it. We build an application that automatically creates a database server where you can transfer
data for further analysis. You can use this example as a basis to build an on-demand data warehouse solution.

xxv

www.it-ebooks.info
■ Introduction

The Example Source Code


The source code of all the examples in this book, along with any applicable sample data, can be downloaded from the
Apress website by following instructions at www.apress.com/source-code/. The source code stored at this location
contains the same code that is described in the book.
Most of the prototypes described in this book are also available as open-source projects. You can find these
projects at the author’s website, http://www.sysadminpy.com/.

xxvi

www.it-ebooks.info
Chapter 1

Reading and Collecting Performance


Data Using SNMP

Most devices that are connected to a network report their status using SNMP (the Simple Network Management
Protocol). This protocol was designed primarily for managing and monitoring network-attached hardware devices,
but some applications also expose their statistical data using this protocol. In this chapter we will look at how to
access this information from your Python applications. We are going to store the obtained data in an RRD (round robin
database), using RRDTool—a widely known and popular application and library, which is used to store and plot the
performance data. Finally we’ll investigate the Jinja2 template system, which we’ll use to generate simple web pages
for our application.

Application Requirements and Design


The topic of system monitoring is very broad and usually encompasses many different areas. A complete monitoring
system is rather complex and often is made up of multiple components working together. We are not going to develop
a complete, self-sufficient system here, but we’ll look into two important areas of a typical monitoring system:
information gathering and representation. In this chapter we’ll implement a system that queries devices using an
SNMP protocol and then stores the data using the RRDTool library, which is also used to generate the graphs for visual
data representation. All this is tied together into simple web pages using the Jinja2 templating library. We’ll look at
each of these components in more detail as we go along through the chapter.

Specifying the Requirements


Before we start designing our application we need to come up with some requirements for our system. First of all
we need to understand the functionality we expect our system to provide. This will help us to create an effective
(and we hope easy-to-implement) system design. In this chapter we are going to create a system that monitors
network-attached devices, such as network switches and routers, using the SNMP protocol. So the first requirement
is that the system be able to query any device using SNMP.
The information gathered from the devices needs to be stored for future reference and analysis. Let’s make
some assumptions about the use of this information. First, we don’t need to store it indefinitely. (I’ll talk more about
permanent information storage in Chapters 9–11.) This means that the information is stored only for a predefined
period of time, and once it becomes obsolete it will be erased. This presents our second requirement: the information
needs to be deleted after it has “expired.”
Second, the information needs to be stored so that graphs can be produced. We are not going to use it for
anything else, and therefore the data store should be optimized for the data representation tasks.

www.it-ebooks.info
Chapter 1 ■ Reading and Collecting Performance Data Using SNMP

Finally, we need to generate the graphs and represent this information on easily accessible web pages. The
information needs to be structured by the device names only. For example, if we are monitoring several devices for CPU
and network interface utilization, this information needs to be presented on a single page. We don’t need to present this
information on multiple time scales; by default the graphs should show the performance indicators for the last 24 hours.

High-Level Design Specification


Now that we have some ideas about the functionality of our system, let’s create a simple design, which we’ll use as a
guide in the development phase. The basic approach is that each of the requirements we specified earlier should be
covered by one or more design decisions.
The first requirement is that we need to monitor the network-attached devices, and we need to do so using SNMP.
This means that we have to use appropriate Python library that deals with the SNMP objects. The SNMP module is not
included in the default Python installation, so we’ll have to use one of the external modules. I recommend using the
PySNMP library (available at http://pysnmp.sourceforge.net/), which is readily available on most of the popular
Linux distributions.
The perfect candidate for the data store engine is RRDTool (available at http://oss.oetiker.ch/rrdtool/).
The round robin database means that the database is structured in such a way that each “table” has a limited length,
and once the limit is reached, the oldest entries are dropped. In fact they are not dropped; the new ones are simply
written into their position.
The RRDTool library provides two distinct functionalities: the database service and the graph-generation toolkit.
There is no native support for RRD databases in Python, but there is an external library available that provides an
interface to the RRDTool library.
Finally, to generate the web page we will use the Jinja2 templating library (available at http://jinja.pocoo.org,
or on GitHub: https://github.com/mitsuhiko/jinja2), which lets us create sophisticated templates and decouple
the design and development tasks.
We are going to use a simple Windows INI-style configuration file to store the information about the devices
we will be monitoring. This information will include details such as the device address, SNMP object reference, and
access control details.
The application will be split into two parts: the first part is the information-gathering tool that queries all
configured devices and stores the data in the RRDTool database, and the second part is the report generator, which
generates the web site structure along with all required images. Both components will be instantiated from the
standard UNIX scheduler application, cron. These two scripts will be named snmp-manager.py and
snmp-pages.py, respectively.

Introduction to SNMP
SNMP (Simple Network Management Protocol) is a UDP-based protocol used mostly for managing network-attached
devices, such as routers, switches, computers, printers, video cameras, and so on. Some applications also allow access
to internal counters via the SNMP protocol.
SNMP not only allows you to read performance statistics from the devices, it can also send control messages to
instruct a device to perform some action—for example, you can restart a router remotely by using SNMP commands.
There are three main components in a system managed by SIMPLE NETWORK MANAGEMENT
PROTOCOL (SNMP):
• The management system which is responsible for managing all devices
• The managed devices, which are all devices managed by the management system
• The SNMP agent, which is an application that runs on each of the managed devices and
interacts with the management system
This relationship is illustrated in Figure 1-1.

www.it-ebooks.info
Chapter 1 ■ Reading and Collecting Performance Data Using SNMP

The Management
System

SNMP Agent SNMP Agent SNMP Agent


software software ... software

Managed device 1 Managed device 2 Managed device X

Figure 1-1. The SNMP network components

This approach is rather generic. The protocol defines seven basic commands, of which the most interesting to us
are get, get bulk, and response. As you may have guessed, the former two are the commands that the management
system issues to the agent, and the latter is a response from the agent software.
How does the management system know what to look for? The protocol does not define a way of exchanging
this information, and therefore the management system has no way to interrogate the agents to obtain the list of
available variables.
The issue is resolved by using a Management Information Base (or MIB). Each device usually has an associated
MIB, which describes the structure of the management data on that system. Such a MIB would list in hierarchical
order all object identifiers (OIDs) that are available on the managed device. The OID effectively represents a node
in the object tree. It contains numerical identifiers of all nodes leading to the current OID starting from the node at
the top of the tree. The node IDs are assigned and regulated by the IANA (Internet Assigned Numbers Authority).
An organization can apply for an OID node, and when it is assigned it is responsible for managing the OID structure
below the allocated node.
Figure 1-2 illustrates a portion of the OID tree.

www.it-ebooks.info
Chapter 1 ■ Reading and Collecting Performance Data Using SNMP

ROOT

CCITT(0) ISO (1) CCITT-ISO (2)

ORG (3)

DOD (6)

INTERNET (1)

Directory (1) Mgmt (2) Experimental (3) Private (4)

Enterprise (1) Enterprise (1)

Cisco (9) Novell (23)

System (1)

Interfaces (2)
sysDescr (1) sysUpTime (3)

ifNumber (1) ifTable (2)


sysObjectID (2)

ifEntry (1)

ifIndex (1) ifDesc (2) ifType (3)

Figure 1-2. The SNMP OID tree

Let’s look at some example OIDs. The OID tree node that is assigned to the Cisco organization has a value of
1.3.6.1.4.1.9, which means that all proprietary OIDs that are associated with the Cisco manufactured devices will start
with these numbers. Similarly, the Novell devices will have their OIDs starting with 1.3.6.1.4.1.23.
I deliberately emphasized proprietary OIDs because some properties are expected to be present (if and where
available) on all devices. These are under the 1.3.6.1.2.1.1 (System SNMP Variables) node, which is defined by
RFC1213. For more details on the OID tree and its elements, visit http://www.alvestrand.no/objectid/top.html.
This website allows you to browse the OID tree and it contains quite a large collection of the various OIDs.

The System SNMP Variables Node


In most cases the basic information about a device will be available under the System SNMP Variables OID node
subtree. Therefore let’s have a close look at what you can find there.
This OID node contains several additional OID nodes. Table 1-1 provides a description for most of the subnodes.

www.it-ebooks.info
Chapter 1 ■ Reading and Collecting Performance Data Using SNMP

Table 1-1. System SNMP OIDs

OID String OID Name Description


1.3.6.1.2.1.1.1 sysDescr A string containing a short description of the system or device.
Usually contains the hardware type and operating system details.
1.3.6.1.2.1.1.2 sysObjectID A string containing the vendor-specific device OID node. For example,
if the organization has been assigned an OID node 1.3.6.1.4.1.8888
and this specific device has been assigned a .1.1 OID space under
the organization’s space, this field would contain a value of
1.3.6.1.4.1.8888.1.1.
1.3.6.1.2.1.1.3 sysUpTime A number representing the time in hundreds of a second from the time
when the system was initialized.
1.3.6.1.2.1.1.4 sysContact An arbitrary string containing information about the contact person
who is responsible for this system.
1.3.6.1.2.1.1.5 sysName A name that has been assigned to the system. Usually this field contains
a fully qualified domain name.
1.3.6.1.2.1.1.6 sysLocation A string describing the physical location of the system.
1.3.6.1.2.1.1.7 sysServices A number that indicates which services are offered by this system.
The number is a bitmap representation of all OSI protocols, with the
lowest bit representing the first OSI layer. For example, a switching
device (operating on layer 2) would have this number set to 22 = 4.
This field is rarely used now.
1.3.6.1.2.1.1.8 sysLastChange A number containing the value of sysUpTime at the time of a change to
any of the system SNMP objects.
1.3.6.1.2.1.1.9 sysTable A node containing multiple sysEntry elements. Each element
represents a distinct capability and the corresponding OID node value.

The Interfaces SNMP Variables Node


Similarly, the basic interface statistics can be obtained from the Interfaces SNMP Variables OID node subtree.
The OID for the interfaces variables is 1.3.6.1.2.1.2 and contains two subnodes:
• An OID containing the total number of network interfaces. The OID value for this entry is
1.3.6.1.2.1.2.1; and it is usually referenced as ifNumber. There are no subnodes available
under this OID.
• An OID node that contains all interface entries. Its OID is 1.3.6.1.2.1.2.2 and it is usually
referenced as ifTable. This node contains one or more entry nodes. An entry node
(1.3.6.1.2.1.2.2.1, also known as ifEntry) contains the detailed information about that
particular interface. The number of entries in the list is defined by the ifNumber node value.
You can find detailed information about all ifEntry subnodes in Table 1-2.

www.it-ebooks.info
Chapter 1 ■ Reading and Collecting Performance Data Using SNMP

Table 1-2. Interface entry SNMP OIDs

OID String OID Name Description


1.3.6.1.2.1.2.2.1.1 ifIndex A unique sequence number assigned to the interface.
1.3.6.1.2.1.2.2.1.2 ifDescr A string containing the interface name and other available
information, such as the hardware manufacturer’s name.
1.3.6.1.2.1.2.2.1.3 ifType A number representing the interface type, depending on the
interface’s physical link and protocol.
1.3.6.1.2.1.2.2.1.4 ifMtu The largest network datagram that this interface can transmit.
1.3.6.1.2.1.2.2.1.5 ifSpeed The estimated current bandwidth of the interface. If the current
bandwidth cannot be calculated, this number should contain the
maximum possible bandwidth for the interface.
1.3.6.1.2.1.2.2.1.6 ifPhysAddress The physical address of the interface, usually a MAC address on
Ethernet interfaces.
1.3.6.1.2.1.2.2.1.7 ifAdminStatus This OID allows setting the new state of the interface. Usually
limited to the following values: 1 (Up), 2 (Down), 3 (Testing).
1.3.6.1.2.1.2.2.1.8 ifOperStatus The current state of the interface. Usually limited to the following
values: 1 (Up), 2 (Down), 3 (Testing).
1.3.6.1.2.1.2.2.1.9 ifLastChange The value containing the system uptime (sysUpTime) reading when
this interface entered its current state. May be set to zero if the
interface entered this state before the last system reinitialization.
1.3.6.1.2.1.2.2.1.10 ifInOctets The total number of bytes (octets) received on the interface.
1.3.6.1.2.1.2.2.1.11 ifInUcastPkts The number of unicast packets forwarded to the device’s
network stack.
1.3.6.1.2.1.2.2.1.12 ifInNUcastPkts The number of non-unicast packets delivered to the device’s
network stack. Non-unicast packets are usually either broadcast or
multicast packets.
1.3.6.1.2.1.2.2.1.13 ifInDiscards The number of dropped packets. This does not indicate a packet
error, but may indicate that the receive buffer was too small to
accept the packets.
1.3.6.1.2.1.2.2.1.14 ifInErrors The number of received invalid packets.
1.3.6.1.2.1.2.2.1.15 ifInUnknownProtos The number of packets that were dropped because the protocol is
not supported on the device interface.
1.3.6.1.2.1.2.2.1.16 ifOutOctets The number of bytes (octets) transmitted out of the interface.
1.3.6.1.2.1.2.2.1.17 ifOutUcastPkts The number of unicast packets received from the device’s network
stack. This number also includes the packets that were discarded
or not sent.

(continued)

www.it-ebooks.info
Chapter 1 ■ Reading and Collecting Performance Data Using SNMP

Table 1-2. (continued)

OID String OID Name Description


1.3.6.1.2.1.2.2.1.18 ifNUcastPkts The number of non-unicast packets received from the device’s
network stack. This number also includes the packets that were
discarded or not sent.
1.3.6.1.2.1.2.2.1.19 ifOutDiscards The number of valid packets that were discarded. It’s not an error,
but it may indicate that the send buffer is too small to accept all
packets.
1.3.6.1.2.1.2.2.1.20 ifOutErrors The number of outgoing packets that couldn’t be transmitted
because of the errors.
1.3.6.1.2.1.2.2.1.21 ifOutQLen The length of the outbound packet queue.
1.3.6.1.2.1.2.2.1.22 ifSpecific Usually contains a reference to the vendor-specific OID describing
this interface. If such information is not available the value is set
to an OID 0.0, which is syntactically valid, but is not pointing to
anything.

Authentication in SNMP
Authentication in earlier SNMP implementations is somewhat primitive and is prone to attacks. An SNMP agent
defines two community strings: one for read-only access and the other for read/write access. When the management
system connects to the agent, it must authenticate with one of those two strings. The agent accepts commands only
from a management system that has authenticated with valid community strings.

Querying SNMP from the Command Line


Before we start writing our application, let’s quickly look at how to query SNMP from the command line. This is
particularly useful if you want to check whether the information returned by the SNMP agent is correctly accepted by
your application.
The command-line tools are provided by the Net-SNMP-Utils package, which is available for most Linux
distributions. This package includes the tools to query and set SNMP objects. Consult your Linux distribution
documentation for the details on installing this package. For example, on a RedHat-based system you can install these
tools with the following command:

$ sudo yum install net-snmp-utils

On a Debian-based system the package can be installed like this:

$ sudo apt-get install snmp

The most useful command from this package is snmpwalk, which takes an OID node as an argument and tries
to discover all subnode OIDs. This command uses the SNMP operation getnext, which returns the next node in the
tree and effectively allows you to traverse the whole subtree from the indicated node. If no OID has been specified,
snmpwalk will use the default SNMP system OID (1.3.6.1.2.1) as the starting point. Listing 1-1 demonstrates the
snmpwalk command issued against a laptop running Fedora Linux.

www.it-ebooks.info
Chapter 1 ■ Reading and Collecting Performance Data Using SNMP

Listing 1-1. An Example of the snmpwalk Command


$ snmpwalk –v2c -c public -On 192.168.1.68
.1.3.6.1.2.1.1.1.0 = STRING: Linux fedolin.example.com 2.6.32.11-99.fc12.i686 #1
SMP Mon Apr 5 16:32:08 EDT 2010 i686
.1.3.6.1.2.1.1.2.0 = OID: .1.3.6.1.4.1.8072.3.2.10
.1.3.6.1.2.1.1.3.0 = Timeticks: (110723) 0:18:27.23
.1.3.6.1.2.1.1.4.0 = STRING: Administrator (admin@example.com)
.1.3.6.1.2.1.1.5.0 = STRING: fedolin.example.com
.1.3.6.1.2.1.1.6.0 = STRING: MyLocation, MyOrganization, MyStreet, MyCity, MyCountry
.1.3.6.1.2.1.1.8.0 = Timeticks: (3) 0:00:00.03
.1.3.6.1.2.1.1.9.1.2.1 = OID: .1.3.6.1.6.3.10.3.1.1
.1.3.6.1.2.1.1.9.1.2.2 = OID: .1.3.6.1.6.3.11.3.1.1
.1.3.6.1.2.1.1.9.1.2.3 = OID: .1.3.6.1.6.3.15.2.1.1
.1.3.6.1.2.1.1.9.1.2.4 = OID: .1.3.6.1.6.3.1
.1.3.6.1.2.1.1.9.1.2.5 = OID: .1.3.6.1.2.1.49
.1.3.6.1.2.1.1.9.1.2.6 = OID: .1.3.6.1.2.1.4
.1.3.6.1.2.1.1.9.1.2.7 = OID: .1.3.6.1.2.1.50
.1.3.6.1.2.1.1.9.1.2.8 = OID: .1.3.6.1.6.3.16.2.2.1
.1.3.6.1.2.1.1.9.1.3.1 = STRING: The SNMP Management Architecture MIB.
.1.3.6.1.2.1.1.9.1.3.2 = STRING: The MIB for Message Processing and Dispatching.
.1.3.6.1.2.1.1.9.1.3.3 = STRING: The management information definitions for the
SNMP User-based Security Model.
.1.3.6.1.2.1.1.9.1.3.4 = STRING: The MIB module for SNMPv2 entities
.1.3.6.1.2.1.1.9.1.3.5 = STRING: The MIB module for managing TCP implementations
.1.3.6.1.2.1.1.9.1.3.6 = STRING: The MIB module for managing IP and ICMP
implementations
.1.3.6.1.2.1.1.9.1.3.7 = STRING: The MIB module for managing UDP implementations
.1.3.6.1.2.1.1.9.1.3.8 = STRING: View-based Access Control Model for SNMP.
.1.3.6.1.2.1.1.9.1.4.1 = Timeticks: (3) 0:00:00.03
.1.3.6.1.2.1.1.9.1.4.2 = Timeticks: (3) 0:00:00.03
.1.3.6.1.2.1.1.9.1.4.3 = Timeticks: (3) 0:00:00.03
.1.3.6.1.2.1.1.9.1.4.4 = Timeticks: (3) 0:00:00.03
.1.3.6.1.2.1.1.9.1.4.5 = Timeticks: (3) 0:00:00.03
.1.3.6.1.2.1.1.9.1.4.6 = Timeticks: (3) 0:00:00.03
.1.3.6.1.2.1.1.9.1.4.7 = Timeticks: (3) 0:00:00.03
.1.3.6.1.2.1.1.9.1.4.8 = Timeticks: (3) 0:00:00.03
.1.3.6.1.2.1.2.1.0 = INTEGER: 5
.1.3.6.1.2.1.2.2.1.1.1 = INTEGER: 1
.1.3.6.1.2.1.2.2.1.1.2 = INTEGER: 2
.1.3.6.1.2.1.2.2.1.1.3 = INTEGER: 3
.1.3.6.1.2.1.2.2.1.1.4 = INTEGER: 4
.1.3.6.1.2.1.2.2.1.1.5 = INTEGER: 5
.1.3.6.1.2.1.2.2.1.2.1 = STRING: lo
.1.3.6.1.2.1.2.2.1.2.2 = STRING: eth0
.1.3.6.1.2.1.2.2.1.2.3 = STRING: wlan1
.1.3.6.1.2.1.2.2.1.2.4 = STRING: pan0
.1.3.6.1.2.1.2.2.1.2.5 = STRING: virbr0
.1.3.6.1.2.1.2.2.1.3.1 = INTEGER: softwareLoopback(24)
.1.3.6.1.2.1.2.2.1.3.2 = INTEGER: ethernetCsmacd(6)
.1.3.6.1.2.1.2.2.1.3.3 = INTEGER: ethernetCsmacd(6)
.1.3.6.1.2.1.2.2.1.3.4 = INTEGER: ethernetCsmacd(6)

www.it-ebooks.info
Chapter 1 ■ Reading and Collecting Performance Data Using SNMP

.1.3.6.1.2.1.2.2.1.3.5 = INTEGER: ethernetCsmacd(6)


.1.3.6.1.2.1.2.2.1.4.1 = INTEGER: 16436
.1.3.6.1.2.1.2.2.1.4.2 = INTEGER: 1500
.1.3.6.1.2.1.2.2.1.4.3 = INTEGER: 1500
.1.3.6.1.2.1.2.2.1.4.4 = INTEGER: 1500
.1.3.6.1.2.1.2.2.1.4.5 = INTEGER: 1500
.1.3.6.1.2.1.2.2.1.5.1 = Gauge32: 10000000
.1.3.6.1.2.1.2.2.1.5.2 = Gauge32: 0
.1.3.6.1.2.1.2.2.1.5.3 = Gauge32: 10000000
.1.3.6.1.2.1.2.2.1.5.4 = Gauge32: 10000000
.1.3.6.1.2.1.2.2.1.5.5 = Gauge32: 10000000
.1.3.6.1.2.1.2.2.1.6.1 = STRING:
.1.3.6.1.2.1.2.2.1.6.2 = STRING: 0:d:56:7d:68:b0
.1.3.6.1.2.1.2.2.1.6.3 = STRING: 0:90:4b:64:7b:4d
.1.3.6.1.2.1.2.2.1.6.4 = STRING: 4e:e:b8:9:81:3b
.1.3.6.1.2.1.2.2.1.6.5 = STRING: d6:f9:7c:2c:17:28
.1.3.6.1.2.1.2.2.1.7.1 = INTEGER: up(1)
.1.3.6.1.2.1.2.2.1.7.2 = INTEGER: up(1)
.1.3.6.1.2.1.2.2.1.7.3 = INTEGER: up(1)
.1.3.6.1.2.1.2.2.1.7.4 = INTEGER: down(2)
.1.3.6.1.2.1.2.2.1.7.5 = INTEGER: up(1)
.1.3.6.1.2.1.2.2.1.8.1 = INTEGER: up(1)
.1.3.6.1.2.1.2.2.1.8.2 = INTEGER: down(2)
.1.3.6.1.2.1.2.2.1.8.3 = INTEGER: up(1)
.1.3.6.1.2.1.2.2.1.8.4 = INTEGER: down(2)
.1.3.6.1.2.1.2.2.1.8.5 = INTEGER: up(1)
.1.3.6.1.2.1.2.2.1.9.1 = Timeticks: (0) 0:00:00.00
.1.3.6.1.2.1.2.2.1.9.2 = Timeticks: (0) 0:00:00.00
.1.3.6.1.2.1.2.2.1.9.3 = Timeticks: (0) 0:00:00.00
.1.3.6.1.2.1.2.2.1.9.4 = Timeticks: (0) 0:00:00.00
.1.3.6.1.2.1.2.2.1.9.5 = Timeticks: (0) 0:00:00.00
.1.3.6.1.2.1.2.2.1.10.1 = Counter32: 89275
.1.3.6.1.2.1.2.2.1.10.2 = Counter32: 0
.1.3.6.1.2.1.2.2.1.10.3 = Counter32: 11649462
.1.3.6.1.2.1.2.2.1.10.4 = Counter32: 0
.1.3.6.1.2.1.2.2.1.10.5 = Counter32: 0
.1.3.6.1.2.1.2.2.1.11.1 = Counter32: 1092
.1.3.6.1.2.1.2.2.1.11.2 = Counter32: 0
.1.3.6.1.2.1.2.2.1.11.3 = Counter32: 49636
.1.3.6.1.2.1.2.2.1.11.4 = Counter32: 0
.1.3.6.1.2.1.2.2.1.11.5 = Counter32: 0
.1.3.6.1.2.1.2.2.1.12.1 = Counter32: 0
.1.3.6.1.2.1.2.2.1.12.2 = Counter32: 0
.1.3.6.1.2.1.2.2.1.12.3 = Counter32: 0
.1.3.6.1.2.1.2.2.1.12.4 = Counter32: 0
.1.3.6.1.2.1.2.2.1.12.5 = Counter32: 0
.1.3.6.1.2.1.2.2.1.13.1 = Counter32: 0
.1.3.6.1.2.1.2.2.1.13.2 = Counter32: 0
.1.3.6.1.2.1.2.2.1.13.3 = Counter32: 0
.1.3.6.1.2.1.2.2.1.13.4 = Counter32: 0
.1.3.6.1.2.1.2.2.1.13.5 = Counter32: 0
.1.3.6.1.2.1.2.2.1.14.1 = Counter32: 0

www.it-ebooks.info
Chapter 1 ■ Reading and Collecting Performance Data Using SNMP

.1.3.6.1.2.1.2.2.1.14.2 = Counter32: 0
.1.3.6.1.2.1.2.2.1.14.3 = Counter32: 0
.1.3.6.1.2.1.2.2.1.14.4 = Counter32: 0
.1.3.6.1.2.1.2.2.1.14.5 = Counter32: 0
.1.3.6.1.2.1.2.2.1.15.1 = Counter32: 0
.1.3.6.1.2.1.2.2.1.15.2 = Counter32: 0
.1.3.6.1.2.1.2.2.1.15.3 = Counter32: 0
.1.3.6.1.2.1.2.2.1.15.4 = Counter32: 0
.1.3.6.1.2.1.2.2.1.15.5 = Counter32: 0
.1.3.6.1.2.1.2.2.1.16.1 = Counter32: 89275
.1.3.6.1.2.1.2.2.1.16.2 = Counter32: 0
.1.3.6.1.2.1.2.2.1.16.3 = Counter32: 922277
.1.3.6.1.2.1.2.2.1.16.4 = Counter32: 0
.1.3.6.1.2.1.2.2.1.16.5 = Counter32: 3648
.1.3.6.1.2.1.2.2.1.17.1 = Counter32: 1092
.1.3.6.1.2.1.2.2.1.17.2 = Counter32: 0
.1.3.6.1.2.1.2.2.1.17.3 = Counter32: 7540
.1.3.6.1.2.1.2.2.1.17.4 = Counter32: 0
.1.3.6.1.2.1.2.2.1.17.5 = Counter32: 17
.1.3.6.1.2.1.2.2.1.18.1 = Counter32: 0
.1.3.6.1.2.1.2.2.1.18.2 = Counter32: 0
.1.3.6.1.2.1.2.2.1.18.3 = Counter32: 0
.1.3.6.1.2.1.2.2.1.18.4 = Counter32: 0
.1.3.6.1.2.1.2.2.1.18.5 = Counter32: 0
.1.3.6.1.2.1.2.2.1.19.1 = Counter32: 0
.1.3.6.1.2.1.2.2.1.19.2 = Counter32: 0
.1.3.6.1.2.1.2.2.1.19.3 = Counter32: 0
.1.3.6.1.2.1.2.2.1.19.4 = Counter32: 0
.1.3.6.1.2.1.2.2.1.19.5 = Counter32: 0
.1.3.6.1.2.1.2.2.1.20.1 = Counter32: 0
.1.3.6.1.2.1.2.2.1.20.2 = Counter32: 0
.1.3.6.1.2.1.2.2.1.20.3 = Counter32: 0
.1.3.6.1.2.1.2.2.1.20.4 = Counter32: 0
.1.3.6.1.2.1.2.2.1.20.5 = Counter32: 0
.1.3.6.1.2.1.2.2.1.21.1 = Gauge32: 0
.1.3.6.1.2.1.2.2.1.21.2 = Gauge32: 0
.1.3.6.1.2.1.2.2.1.21.3 = Gauge32: 0
.1.3.6.1.2.1.2.2.1.21.4 = Gauge32: 0
.1.3.6.1.2.1.2.2.1.21.5 = Gauge32: 0
.1.3.6.1.2.1.2.2.1.22.1 = OID: .0.0
.1.3.6.1.2.1.2.2.1.22.2 = OID: .0.0
.1.3.6.1.2.1.2.2.1.22.3 = OID: .0.0
.1.3.6.1.2.1.2.2.1.22.4 = OID: .0.0
.1.3.6.1.2.1.2.2.1.22.5 = OID: .0.0
.1.3.6.1.2.1.25.1.1.0 = Timeticks: (8232423) 22:52:04.23
.1.3.6.1.2.1.25.1.1.0 = No more variables left in this MIB View (It is past the end
of the MIB tree)

As an exercise, try to identify some of the listed OIDs using Tables 1-1 and 1-2 and find out what they mean.

10

www.it-ebooks.info
Chapter 1 ■ Reading and Collecting Performance Data Using SNMP

Querying SNMP Devices from Python


Now we know enough about SNMP to start working on our own management system, which will be querying the
configured systems on regular intervals. First let’s specify the configuration that we will be using in the application.

Configuring the Application


As we already know, we need the following information available for every check:
• An IP address or resolvable domain name of the system that runs the SNMP agent software
• The read-only community string that will be used to authenticate with the agent software
• The OID node’s numerical representation
We are going to use the Windows INI-style configuration file because of its simplicity. Python includes a
configuration parsing module by default, so it is also convenient to use. (Chapter 9 discusses the ConfigParser
module in great detail; refer to that chapter for more information about the module.)
Let’s go back to the configuration file for our application. There is no need to repeat the system information for
every SNMP object that we’re going to query, so we can define each system parameter once in a separate section and
then refer to the system ID in each check section. The check section defines the OID node identifier string and a short
description, as shown in Listing 1-2. Create a configuration file called snmp-manage.cfg with the contents from the
listing below; don’t forget to modify the IP and security details accordingly.

Listing 1-2. The Management System Configuration File


[system_1]
description=My Laptop
address=192.168.1.68
port=161
communityro=public

[check_1]
description=WLAN incoming traffic
oid=1.3.6.1.2.1.2.2.1.10.3
system=system_1

[check_2]
description=WLAN incoming traffic
oid=1.3.6.1.2.1.2.2.1.16.3
system=system_1

Make sure that the system and check section IDs are unique, or you may get unpredictable results.
We’re going to create an SnmpManager class with two methods, one to add a system and the other to add a check.
As the check contains the system ID string, it will automatically be assigned to that particular system. In Listing 1-3
you can see the class definition and also the initialization part that reads in the configuration and iterates through the
sections and updates the class object accordingly. Create a file called snmp-manage.py with the contents shown in the
listing below. We will work on adding new features to the script as we go along.

11

www.it-ebooks.info
Chapter 1 ■ Reading and Collecting Performance Data Using SNMP

Listing 1-3. Reading and Storing the Configuration


import sys
from ConfigParser import SafeConfigParser
  
class SnmpManager:
def __init__(self):
self.systems = {}

def add_system(self, id, descr, addr, port, comm_ro):


self.systems[id] = {'description' : descr,
'address' : addr,
'port' : int(port),
'communityro' : comm_ro,
'checks' : {}
}

def add_check(self, id, oid, descr, system):


oid_tuple = tuple([int(i) for i in oid.split('.')])
self.systems[system]['checks'][id] = {'description': descr,
'oid' : oid_tuple,
}

def main(conf_file=""):
if not conf_file:
sys.exit(-1)
config = SafeConfigParser()
config.read(conf_file)
snmp_manager = SnmpManager()
for system in [s for s in config.sections() if s.startswith('system')]:
snmp_manager.add_system(system,
config.get(system, 'description'),
config.get(system, 'address'),
config.get(system, 'port'),
config.get(system, 'communityro'))
for check in [c for c in config.sections() if c.startswith('check')]:
snmp_manager.add_check(check,
config.get(check, 'oid'),
config.get(check, 'description'),
config.get(check, 'system'))

if __name__ == '__main__':
main(conf_file='snmp-manager.cfg')

As you see in the example, we first have to iterate through the system sections and update the object before
proceeding with the check sections.

■■Note This order is important, because if we try to add a check for a system that hasn’t been inserted yet, we’ll get a
dictionary index error.

12

www.it-ebooks.info
Chapter 1 ■ Reading and Collecting Performance Data Using SNMP

Also note that we are converting the OID string to a tuple of integers. You’ll see why we have to do this later in this
section. The configuration file is loaded and we’re ready to run SNMP queries against the configured devices.

Using the PySNMP Library


In this project we are going to use the PySNMP library, which is implemented in pure Python and doesn’t depend on
any precompiled libraries. The pysnmp package is available for most Linux distributions and can be installed using the
standard distribution package manager. In addition to pysnmp you will also need the ASN.1 library, which is used by
pysnmp and is also available as part of the Linux distribution package selection. For example, on a Fedora system you
can install the pysnmp module with the following commands:

$ sudo yum install pysnmp


$ sudo yum install python-pyasn1

Alternatively, you can use the Python Package manager (PiP) to install this library for you:

$ sudo pip install pysnmp


$ sudo pip install pyasn1

If you don’t have the pip command available, you can download and install this tool from
http://pypi.python.org/pypi/pip. We will use it in later chapters as well.
The PySNMP library hides all the complexity of SNMP processing behind a single class with a simple API.
All you have to do is create an instance of the CommandGenerator class. This class is available from the
pysnmp.entity.rfc3413.oneliner.cmdgen module and implements most of the standard SNMP protocol
commands: getCmd(), setCmd(), and nextCmd(). Let’s look at each of these in more detail.

The SNMP GET Command


All the commands we are going to discuss follow the same invocation pattern: import the module, create an instance
of the CommandGenerator class, create three required parameters (an authentication object, a transport target
object, and a list of arguments), and finally invoke the appropriate method. The method returns a tuple containing
the error indicators (if there was an error) and the result object.
In Listing 1-4, we query a remote Linux machine using the standard SNMP OID (1.3.6.1.2.1.1.1.0).

Listing 1-4. An Example of the SNMP GET Command


>>> from pysnmp.entity.rfc3413.oneliner import cmdgen
>>> cg = cmdgen.CommandGenerator()
>>> comm_data = cmdgen.CommunityData('my-manager', 'public')
>>> transport = cmdgen.UdpTransportTarget(('192.168.1.68', 161))
>>> variables = (1, 3, 6, 1, 2, 1, 1, 1, 0)
>>> errIndication, errStatus, errIndex, result = cg.getCmd(comm_data, transport, variables)
>>> print errIndication
None
>>> print errStatus
0
>>> print errIndex
0
>>> print result
[(ObjectName('1.3.6.1.2.1.1.1.0'), OctetString('Linux fedolin.example.com
2.6.32.11-99.fc12.i686 #1 SMP Mon Apr 5 16:32:08 EDT 2010 i686'))]
>>>

13

www.it-ebooks.info
Discovering Diverse Content Through
Random Scribd Documents
The Project Gutenberg eBook of Christmas offering
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

Title: Christmas offering

Author: Mrs. Elizabeth Dimond

Release date: December 21, 2020 [eBook #64093]


Most recently updated: October 18, 2024

Language: English

Credits: Charlene Taylor, Chuck Greif and the Online Distributed


Proofreading Team at https://www.pgdp.net (This file
was produced from images generously made available
by The Internet Archive/American Libraries.)

*** START OF THE PROJECT GUTENBERG EBOOK CHRISTMAS


OFFERING ***
A

CHRISTMAS OFFERING:
BY MRS. ELIZABETH DIMOND,

OF BRISTOL, R. I.

PROVIDENCE:
PRINTED BY KNOWLES AND VOSE.
1847.

MRS. SMITH,

Providence, R. I.

Dear Friend:

You may be surprised to hear that your old friend, in

her eighty-fourth year, while musing upon God’s mercy


and wisdom, has brought forth this little poem on

Creation; which, together with others, permit me to


inscribe to you, wishing you a prolongation of the

prosperity and happiness you enjoy.

I am yours, &c.
ELIZABETH DIMOND.

Bristol, R. I., Dec. 18, 1847.


A CHRISTMAS OFFERING.
THOUGHTS ON CREATION.
Says the watchman, “And what of the night?
It often brings seasons of sorrow,
When dark and beclouded with sin;
But ah! it may sweeten to-morrow,
If a ray of God’s favor breaks in.
How dark and how gloomy was Chaos;
But God by his own matchless plan,
Call’d this beautiful world from its darkness,
And did safe on its axle-tree hang!
And Jesus, our Savior, was present,
For his was the word of command;
He spangled those orbs in their greatness,
For good and for glory to man.”
The angels in wonder stood gazing,
Till Sol darts his beams to their view;
“What is there in the East that is blazing—
That pearls all the drops of the dew?”
“ ’Tis the Sun,” Great Messiah then answered,
“ ’Tis the Sun,” say the angels, “ ’tis true;
From thee it beams glory and greatness,
And bears up thy own title too.”

Great Sol, arise! and spread thy lustre high—


Go warm the earth, and decorate the sky!
When thou retir’st, the silver moon will rise,
With pearly radiance, o’er those spangled skies!
Without a cloud to intercept thy way,
Go, clearly shine, and make the evening gay!
God saw his work was great, when it he view’d,
Approved the same, and then pronounced it good.
And why this garden, walled so rich and fair,
With glittering stone that is beyond compare—
With walks, and bowers, and interwoven scenes,
With silver rivulets that roll between,
Tossing their golden pebbles in the stream!
Here richest fruits, in clusters ripe and fair,
And variegated blooms perfume the air;
g p ;
Here beast of every kind, playful yet mute,
And birds with plumage gay, and warbling throat,
Chanting to their Maker with melodious note!
And is the richness of these fruits conceal’d,
That grow spontaneous in this fertile field?
Is no one here these sweets to taste? And none the banquet share?
Within these walls is a majestic form,
Graceful and noble as the rising morn!
Adam! survey thy wond’rous form, and see
The image of thy God is stamped on thee!
Be grateful, then, and be obedient, too;
For this respect is to thy Sov’reign due.
And here are richest fruits in store for thee;
And all is thine, except that hallow’d tree:
And should’st thou touch it, thou shall surely die!
I have pronounced! Ask not the reason why.”
Then Adam bows assent, and walks the rounds,
To view the beauties of these fertile grounds—
He stops to listen to the bubbling stream,
That gently trickles down the sloping green;
And on his way he views the crystal pond
Where gold-fish play.
Delighted with the scene, he looks above,
Adores the greatness of the God of Love.
But day is done:
Beyond the western hills now sinks the sun.
Adam with wonder views the evening scene—
The first fair twilight he had ever seen.
But now with drowsy sleep his eyes are pressed,
For God has sanctioned all creation rest.
In Christian attitude kneels to the shrine,
And offers up his prayers in words divine;
Then to his mossy pillow Adam goes,
Nought to disturb or break his soft repose.
He sleeps secure till morning light appears,
And birds of Paradise salute his ears.
Then o’er some loaded bough his arm he’s flung,
Addressed his Maker ith his morning song
Addressed his Maker with his morning song.
Then to the willow’d meads he did repair,
To view his flocks, and see them gambol there.
With scrutiny, he sees each has a friend;
In his own bosom he thus contends:
But why am I exempt, my mind is good,
And I’ve a speech well to be understood——
But here’s my Sov’reign.” “Adam, answer! why
That downcast look—that soft, expressive sigh?
Will not a Paradise for thee suffice?”
“Great Sov’reign! oft I stand in ecstacy,
Viewing the greatness of thy Deity!
I know thy works are infinite, supreme,
And canst answer every wished for scheme.”
“Adam! I see thy faith is strong;
Speak thy request, nor hesitate too long.”
“A friend, a partner give to sweeten life,
And then these rural scenes are Paradise,
Then, Adam, sleep! and to thee I’ll give
A form for whom thou’lt ever wish to live.
Then from his side the ivory bone he takes,
A beauteous woman of the same he makes.
But O! our hearts are bent on pleasure here—
The disappointment oft times is severe.
But Adam wanders forth we know not where,
And leaves alone the unprotected fair.
The fiend, on search, the separation knew—
“This is my time, and I’ll improve it, too:
Say, beauteous Eve, hast thou no greater mind,
Than to these simple flowers to be confined?
Take this delicious fruit, and then you’ll see
That greater glories are in store for thee.”
“That is forbidden fruit; O no! not I;
For if I eat, then I must surely die.”
“Misrepresented is the fruit I give;
I eat the same, and yet you see I live.”
Her innocence had never known a lie;
So to his treacherous art she did comply.
She took the apple! When she ate the same,
The poisonous juice had tainted every vein.
But Adam comes.
“Say, lovely Eve, where is thy beauty fled?
Where is the bloom that tinged thy cheek with red?
Who has been here?”
“A treacherous friend! and I believed his lie:
I ate the apple—I alone must die.
In some remotest corner let me be,
And die alone, dear friend, unseen by thee.
Dear Adam, do not grieve;
Perhaps thy God will grant another Eve.”
“No other Eve shall e’er entwine this heart:
Bone of my bone, from thee I cannot part.”
He ate the apple, while all nature grieved,
And every leaf became a sensitive.
But oh, the black’ning cloud to heaven arose,
And all the horror of their sins exposed!
And all was silent till God’s holy Son,
Array’d in glory, to his Father came.
“Father of mercies! let thy will be done:
Oh, cast the sinner’s burden on thy Son;
For I alone their advocate will be,
And their redemption will be found through me.
For when this world is peopled o’er with men,
Then Satan will resume his power again—
So blind their eyes, and cause their hearts to sin.
I will be mortal—I will dwell with them,
And cast this monster to his lowest den.
For on the cross sinners will raise me high:
For their redemption willingly I die.”
But what does God require for sins like this?
Believe and live, and Christ secures the bliss.
SWEET HOME.

This permanent home! O the thoughts how sublime;


To chant with the angels with voices divine!
To know as we’re known—how delightful the scene,
Where no sin and no sorrow can there intervene.
Home, home, sweet, sweet home.

Dear Jesus, our guide, thou hast purchas’d this home,


By thy blood-streaming side our redemption was won;
Draw us by the cords, all bedew’d with thy love,
Then safe we shall rest in thy bosom above.
Home, home, sweet, sweet home.

Our Father has told us, in accents of love,


To look to the star that doth glitter above.
No eye ever saw, and no heart can conceive,
Of the glory unfolded to saints that believe.
Home, home, sweet, sweet home.
ON THE DEPARTURE OF MY GRANDSON.

And is this little darling doomed to roam,


And cross the treacherous ocean for a home?
And must the cruel barque his cradle be?
And must the billows waft him far from me?

How oft, when grief has crowded round my heart,


I have caressed him, to forget a part:
How oft I’ve long’d his dear departed sire
Could view these fleeting charms that I so much admire.

I, in the infant, could the father see;


Which binds the tie so doubly dear to me.
Oh, thou auspicious Power! send thou thy aid—
Protect the worthy mother and the babe.

Oh, thou bright orb of night! be thou their light,


To guide the helmsman in his onward flight;
Then may the father, with unsullied joy,
Clasp in his arms his much loved wife and boy.
ON A FROSTY MORNING.

One frosty morn on window high,


This beauteous leaf was traced
By Nature’s art; her hand supplied
The crystal square to grace.

Angelic Nature, how divine


Thy brilliant beauties be!
No India pearl, though rare refined,
Can vie, bright frost, with thee.
AFTER A SNOW STORM.

Oh, Abby, dear, have you the scene survey’d,


And viewed this beauteous carpet Nature’s made?
Not only in one spot its beauty’s shone,
But every building wears a milk-white dome.

How did you like the grand, majestic throng,[A]


Waving their banners as they wade along?
Their noble bells they called a grand review,
To see this beauteous carpet cut in two.
TO MY GRANDDAUGHTER.

My dearest child, thy features oft I trace,


And view the opening beauties of thy face;
I see thy bosom, as the matchless dove,
Impressed with virtue and the seat of love.

Thy pleasing smile, more sweet than morning dew,


Will gain the heart of him that’s formed for you;
But if the youth should offer you his hand,
Don’t be in haste, but let the bargain stand.

Consult the friend who ever loves you best;


For in her council you may safely rest.
Oh, may your days be cast in Fortune’s bower,
There safely dwell, and bless the tranquil hour.

May Fortune smile, to grace thy peaceful lot,


And strew thy path with sweet forget-me-not.
TO ROSALIE.

Sweet Rosalie, say, will you take


This tiny gift for friendship’s sake?
Yes: Friendship will forever shine,
Upon a brow so fair as thine.

Then may the union lasting be,


Between dear Isabelle and thee.
Oh, I forgot; ’tis sweet May-day,
When Flora paints the mead so gay.

Go to your own romantic bower,


And gather there the choicest flower;
Entwine your wreath with snow-drops, too,
And then ’twill more resemble you.
LINES,
On presenting two Italian images, in the attitude of dancing, with tambourine and bowl in
hand, to a friend.

Dear Madam, we of late have left our homes,


To view the beauties of your stately rooms;
I do admire them! they’re so grand and neat;
And with your kind consent I’ll take a seat.

Seat, did I say? Oh, no; I meant to stand;


Because, dear Madam, we’re at your command.
But where’s Miss China Aster?[B]—that’s too plain;
The sweet-stock Gillyflower shall be her name.
I hear she’s very good, as well as gay;
Perhaps she’ll intercede for us to stay.
And where is grand-mama, who’s so discreet?
We’d bow respectfully before her feet;
And cousin Hannah, she is mild and meek—
Her argument I love; it is so sweet.
Ladies, should you consent for us to light,
The green-room ever would be our delight.
We’re very fond, you know of rural scenes;
And white is beautiful beside the green.
You see we often step the merry dance,
But ’tis with your consent that we advance.
You dislike music, ma’m, we have been told,
And our is simple—centres in the bowl.
Ladies, should you dislike for us to stay,
Kindly conduct us o’er the ferry way.[C]
Madam, my friend upbraids me for my chat;
I have to speak for both. Should you like that?
THE REPLY.
Oh, why are you so far from home,
On this cold night abroad to roam?
Has your behavior been correct?
I am unwilling to suspect.
Walk in. Don’t stand; pray take a seat;
A stranger I will always greet.
You praise my house and call it splendid,
And praise its inmates, too.
If a mere compliment’s intended,
Civility’s your due.
I’ll give you shelter for the night,
And view you by the morning light;
If, on acquaintance, you should prove
Worthy of Madam Flora’s love,
Then grandma will not plead in vain,
Nor cousin H——, with her sweet strain.
Miss Gillyflower will be delighted,
To take in wanderers benighted;
So I consent; call this your home,
Nor ever from your goddess roam;
At her command, among her flowers,
Spend all your thoughtless, playful hours,
Contrasting with her vivid greens,
Your white robe, which transparent seems.
Though music has no charms for me,
I’m not opposed to others’ glee:
You and your friend may dance and sing,
And welcome the return of spring;
And when the General returns,
And gratitude each bosom warms,
Thank him for all the good I’ve done—
For he and I, you know, are one.
Then be content; no boat nor wherry,
Shall take you t’other side the ferry.
LINES,
Addressed to a lady on the arrival of her husband in New York.

How sweet is the dawn of the spring—


Its ordorous blossoms how gay;
The birds on the boughs sweetly sing,
And drive all our sorrows away.

And here are rich blessings anew;


True, Heaven is good and is kind;
The return of your partner to you,
Will bring a sweet peace to your mind.

And oh, how happy he’ll be,


To find you enjoying good health;
For, oh, lovely Sarah, you see
That you are a part of himself.

Your aid, gentle breezes, do lend,


And waft him safe over the sea.
You must not forget, my dear friend,
Who it is that returns him to thee.
TO THE FRIEND OF MY YOUTH.

To thee, my friend, I wish a happy year,


With friendship true, and with a heart sincere;
May this new year a bounteous blessing prove,
And calm the bosom of the friend I love.

May that connubial tie from her be loosed,


Till some fond Damon shall the bondage choose;
And then with care she’ll mind the nicest part—
Join not the hand till you have won the heart.

There needs no caution, then, methinks she’ll say;


And with a flirt she throws my scroll away.
But still I see her take it up anew,
And say, “I’ll read,”—because her heart is true.

The happy year again the theme she’ll lend,


With anxious wishes for our absent friends:
May the dark curtain of the winter scene
Be calmy drawn, and spring-time blessings bring.

Then let the gales be gentle, kind and sure,


And speed the barque on this her destined tour;
While May’s sweet breezes waft them gently home,
Ladened with riches from a foreign clime.

Then their return will crown the jocund year:


Old friends, old scenes, and all they hold most dear
Will crowd around, and fill each heart with love—
Each voice with thanks to him who reigns above.
TO A YOUNG LADY.

My dear young friend, O may you e’er be blest,


And may your bosom be the seat of rest;
May each succeeding day new pleasures bring,
All pure and lovely as returning spring.

A little fortune be your happy lot,


And on a rising green erect your cot;
Around your bower may blooming hawthorn spring,
And intervening flowers fresh fragrance bring.

May deeds of honor crown your frugal board,


And Heaven’s rich blessings be your great reward,
Æolian harps your nightly windows grace,
And softly lull you to your balmy rest.
ON THE DEATH OF AN INFANT.

Sweet Josephine, thou hast left this drear abode,


To be an angel with thy Father, God!
There, in sweet strains, thy little lisping tongue
Will chant the praises angels never sung.
Farewell, dear babe! A last, a long farewell,
Till we in heaven with thee shall ever dwell.
ON SEEING A LOVELY CHILD.

How sweet is the dawn of an infant—


How fondly caressed is the smile;
The mother, though tired and weary,
Forgets all, when blessed with her child.

When the beautiful bud has expanded,


And opens its bloom to our view;
Oh, then we see with advantage,
What Nature intended to do.

And now she can play and can prattle—


With her doll and her toys loves to dwell;
And who upon earth is so happy,
As the dear little girl, Abby Bell.
A WISH FOR THE SAILOR.

May the winds and the waves prove auspicious to thee,


And waft you safe on where your wishes may be;
Then Heaven befriend you, and reward all your toil,
And load up your ship with a pressure of oil.

FOOTNOTES:
[A] After a great fall of snow, sleds, with cattle attached, filled with men and boys,
with floating banners and merry bells, cut their way through the snow; thus making
the streets passable for lighter vehicles, and for foot passengers.
[B] A name applied by a friend, denoting freshness and vivacity. The Gillyflower
united denotes the sweetness of her temper.
[C] “O’er the ferry way,” the residence of my friend’s brother, a delightful farm
situated between Bristol and Newport, called the “Elam Place.”
*** END OF THE PROJECT GUTENBERG EBOOK CHRISTMAS
OFFERING ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States
copyright in these works, so the Foundation (and you!) can copy
and distribute it in the United States without permission and
without paying copyright royalties. Special rules, set forth in the
General Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree
to abide by all the terms of this agreement, you must cease
using and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project Gutenberg™
works in compliance with the terms of this agreement for
keeping the Project Gutenberg™ name associated with the
work. You can easily comply with the terms of this agreement
by keeping this work in the same format with its attached full
Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookfinal.com

You might also like