Wednesday 25 May 2016

File System in UNIX

The UNIX file system is different from the MS-DOS file system. The disk space allotted to a UNIX file system is made of blocks of usually 512 bytes. All the blocks belonging to a file system are divided into following four parts




Boot Block  : Occupies the beginning of the root file system. This block contains a program called
                       bootstrap loader. Bootstrap loader executes when the host machine is booted.

Super Block : Super block contains the state of the file system ie its size, where to find the free space on the file system, how many files it can store etc.

Inode Block(Table) : It follows the super block and gives the internal representation of the file. The information related to these files is stored in a table known as Inode Table on the disk. For each file, there is an inode entry in the table. Each entry is approx 64 bytes and contains details such as
  •     Owner of the file
  •     Type of the file
  •     File access permissions
  •     File access time
  •     Size of the file
  •     Date and time of last access etc
   
Data Block : Data block contains the actual file contents. An allocated block can belong to only one file in the file system.(Size of blocks can vary from 512 bytes to 4K)


Hierarchy of Unix File System:



The Unix file system follows a tree structure with root represented by '/'.
Every non-leaf node is a directory, containing some other files and subdirectories
Every leaf nodes can be empty directories, regular files or special device files.

The main features of a Unix file system:
  •     Hierarchical structure
  •     Create and delete files
  •     Dynamic growth of files
  •     Protection of file data
  •     Treats peripheral devices as files
  •     Keeps track of files using i-node numbers.
  •     Information of files is kept in the i-node block.

File access permissions can be set for 3 classes of users:
  •     File Owner
  •     File Owner’s Group
  •     Others

Permissions on file:
Read (r), Write (w), Execute (x) permissions can be set for each file.

/bin        : Executable System Utilities (sh, cp, rm etc.)
/lib         : Operating System and Programming Libraries.
/dev       : Device Related Files
/etc        : System Configuration files and databases. 
/tmp      : System Scratch Files
/usr       : Home Directories of all users




   ***************************END**************************

Tuesday 24 May 2016

Unix System Architecture

There 4 major components in the Unix system.

Kernal : Monitors and controls the resources of a computer and allocates them among its users in an
              optimal manner.
Shell    : Provides a processing environment for the user programs and acts like a command translator
Utilities : Programs which are used for development purposes
User Applications : Programs written by the user

The above 4 components can be understood better by a layer approach as following:





Layer 1 (Hardware ) : 

This layer is the hardware over which the different OS layers are built. Hardware is not a part of the Unix OS.

Layer 2 (Kernal) :

This layer is the Kernel, which is the most important component of the Unix system. It is a collection of programs which directly communicate with the hardware. It is that part of the Unix system that is loaded into memory first when the system is booted. It manages the system resources, allocates them between users and the processes, decides priorities of different processes etc.

Layer 3 (User Application/Commands): 

This layer contains programs that interact with the Kernel by invoking some system-calls. Basically these programs are Unix commands like wc, grep, find etc.

Layer 4 (Shell):

This layer is called Shell. Technically another Unix command, it is the interpreter of user requests. It takes a command from the user, deciphers it, and communicates with the Kernel to see that the command is executed. It is actually the interface between the user and the kernel, which effectively insulates the user from the knowledge of kernel functions. It also has a programming capability of its own.

The kernel and shell together make the Unix system work. The shell provides a processing environment to the user programs.




Monday 23 May 2016

Python Script to write a xlsx file

we have a python module called XlsxWriter to write multiple worksheet in MS Excel 2007+ xlsx file. This module can be used to write text, numbers, formulas, hyperlinks and charts.
It supports features such as formatting and many more, including:
  •     100% compatible Excel XLSX files.
  •     Full formatting.
  •     Merged cells.
  •     Defined names.
  •     Charts.
  •     Autofilters.
  •     Data validation and drop down lists.
  •     Conditional formatting.
  •     Worksheet PNG/JPEG images.
  •     Rich multi-format strings.
  •     Cell comments.
  •     Integration with Pandas.
  •     Textboxes.
  •     Memory optimization mode for writing large files.

It supports Python 2.5, 2.6, 2.7, 3.1, 3.2, 3.3, 3.4, 3.5, Jython and PyPy and uses standard libraries only.

Installing XlsxWriter:
Using PIP :
$ sudo pip install XlsxWriter

Using Easy_install:
$ sudo easy_install XlsxWriter

Installing from a tarball:

Download the tarball of latest version and keep it into your working directory and run the following commands to install XlsxWriter module. I have downloaded XlsxWriter-0.8.7.tar.gz

$ tar -zxvf XlsxWriter-0.8.7.tar.gz
$ cd XlsxWriter-0.8.7
$ sudo python setup.py install

# Running a sample program

#!/usr/bin/python
import xlsxwriter

workbook = xlsxwriter.Workbook('hello.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write('A1', 'Hello world')

workbook.close()




import xlsxwriter


# Create an new Excel file and add a worksheet.
workbook = xlsxwriter.Workbook('demo.xlsx')
worksheet = workbook.add_worksheet()

# Widen the first column to make the text clearer.
worksheet.set_column('A:A', 20)

# Add a bold format to use to highlight cells.
bold = workbook.add_format({'bold': True})

# Write some simple text.
worksheet.write('A1', 'Hello')

# Text with formatting.
worksheet.write('A2', 'World', bold)

# Write some numbers, with row/column notation.
worksheet.write(2, 0, 123)
worksheet.write(3, 0, 123.456)

# Insert an image.
worksheet.insert_image('B5', 'logo.png')

workbook.close()

Wednesday 11 May 2016

Standard Nagios Plugins

Plugins are compiled executable s or scripts (Perl scripts, shell scripts, etc.) that can be run from a command line to check the status or a host or service. Nagios uses the results from plugins to determine the current status of hosts and services on your network.

Following is list of standard Nagios Plugins, commands and their usages.
Need personal assistance on Nagios? Please contact me at

immukesh72@gmail.com

at very nominal charges

check_by_ssh
check_disk
check_disk_smb
check_dns
check_dummy
check_flexlm
check_ftp
check_http
check_imap
check_ircd
check_load
check_log
check_mailq
check_mrtg
check_mrtgtraf
check_nagios
check_nntp
check_ntp
check_nwstat
check_overcr
check_ping
check_pop
check_procs
check_real
check_rpc
check_sensors
check_smtp
check_ssh
check_swap
check_tcp
check_time
check_udp
check_ups
check_users
check_vsz
check_wave

Following the detailed description of each command with their usage.

Top

check_by_ssh

This plugin will execute a command on a remote host using SSH

Usage:

check_by_ssh [-f46] [-t timeout] [-i identity] [-l user] -H <host> -C <command> [-n name] [-s servicelist] [-O outputfile] [-p port]
check_by_ssh -V prints version info
check_by_ssh -h prints more detailed help

Options:

-H, --hostname=HOST name or IP address of remote host
-C, --command='COMMAND STRING' command to execute on the remote machine
-f tells ssh to fork rather than create a tty
-t, --timeout=INTEGER specify timeout (default: 10 seconds) [optional]
-p, --port=PORT port to connect to on remote system [optional]
-l, --logname=USERNAME SSH user name on remote host [optional]
-i, --identity=KEYFILE identity of an authorized key [optional]
-O, --output=FILE external command file for nagios [optional]
-s, --services=LIST list of nagios service names, separated by ':' [optional]
-n, --name=NAME short name of host in nagios configuration [optional]
-4, --use-ipv4 tell ssh to use IPv4
-6, --use-ipv6 tell ssh to use IPv6

The most common mode of use is to refer to a local identity file with the '-i' option. In this mode, the identity pair should have a null passphrase and the public key should be listed in the authorized_keys file of the remote host. Usually the key will be restricted to running only one command on the remote server. If the remote SSH server tracks invocation agruments, the one remote program may be an agent that can execute additional commands as proxy

To use passive mode, provide multiple '-C' options, and provide all of -O, -s, and -n options (servicelist order must match '-C' options)

Top

check_disk

This plugin will check the percent of used disk space on a mounted file system and generate an alert if percentage is above one of the threshold values.

Usage:

check_disk -w limit -c limit [-p path] [-t timeout] [-m] [--verbose]
check_disk (-h|--help)
check_disk (-V|--version)

Options:

-w, --warning=INTEGER Exit with WARNING status if less than INTEGER kilobytes of disk are free
-w, --warning=PERCENT% Exit with WARNING status if more than PERCENT of disk space is free
-c, --critical=INTEGER Exit with CRITICAL status if less than INTEGER kilobytes of disk are free
-c, --critical=PERCENT% Exit with CRITCAL status if more than PERCENT of disk space is free
-p, --path=PATH, --partition=PARTTION Path or partition (checks all mounted partitions if unspecified)
-m, --mountpoint Display the mountpoint instead of the partition
-v, --verbose Show details for command-line debugging (do not use with nagios server)
-h, --help Print detailed help screen
-V, --version Print version information

Top

check_disk_smb

This plugin will check the percent of used disk space on a mounted file system and generate an alert if percentage is above one of the threshold values.

Usage:

check_disk -w limit -c limit [-p path] [-t timeout] [-m] [--verbose]
check_disk (-h|--help)
check_disk (-V|--version)

Options:

-w, --warning=INTEGER Exit with WARNING status if less than INTEGER kilobytes of disk are free
-w, --warning=PERCENT% Exit with WARNING status if more than PERCENT of disk space is free
-c, --critical=INTEGER Exit with CRITICAL status if less than INTEGER kilobytes of disk are free
-c, --critical=PERCENT% Exit with CRITCAL status if more than PERCENT of disk space is free
-p, --path=PATH, --partition=PARTTION Path or partition (checks all mounted partitions if unspecified)
-m, --mountpoint Display the mountpoint instead of the partition
-v, --verbose Show details for command-line debugging (do not use with nagios server)
-h, --help Print detailed help screen
-V, --version Print version information

Top

check_dns

Usage:

check_dns -H host [-s server] [-a expected-address] [-t timeout]
check_dns --help
check_dns --version

Option:

-H, --hostname=HOST The name or address you want to query
-s, --server=HOST Optional DNS server you want to use for the lookup
-a, --expected-address=IP-ADDRESS Optional IP address you expect the DNS server to return
-t, --timeout=INTEGER Seconds before connection times out (default: 10)
-h, --help Print detailed help
-V, --version Print version numbers and license information

This plugin uses the nslookup program to obtain the IP address for the given host/domain query. A optional DNS server to use may be specified. If no DNS server is specified, the default server(s) specified in /etc/resolv.conf will be used.

Top

check_dummy

Usage:

./check_dummy <integer state>

This plugin will simply return the state corresponding to the numeric value of the <state> argument.

Top

check_flexlm

Check available flexlm license managers

Usage:

check_flexlm -F <filename> [--verbose]
check_flexlm --help
check_flexlm --version

Options:

-F, --filename=FILE Name of license file
-v, --verbose Print some extra debugging information (not advised for normal operation)
-V, --version Show version and license information
-h, --help Show this help screen

Top

check_ftp

This plugin tests FTP connections with the specified host.

Usage:

check_ftp -H host -p port [-w warn_time] [-c crit_time] [-s send] [-e expect] [-W wait] [-t to_sec] [-v]

Options:

-H, --hostname=ADDRESS Host name argument for servers using host headers (use numeric
address if possible to bypass DNS lookup).
-p, --port=INTEGER Port number
-s, --send=STRING String to send to the server
-e, --expect=STRING String to expect in server response -W, --wait=INTEGER Seconds to wait between sending string and polling for response
-w, --warning=DOUBLE Response time to result in warning status (seconds)
-c, --critical=DOUBLE Response time to result in critical status (seconds)
-t, --timeout=INTEGER Seconds before connection times out (default: 10)
-v Show details for command-line debugging (do not use with nagios server)
-h, --help Print detailed help screen
-V, --version Print version information

Top

check_http

This plugin tests the HTTP service on the specified host. It can test normal (http) and secure (https) servers, follow redirects, search for strings and regular expressions, check connection times, and report on
certificate expiration times.

Usage:

check_http (-H <vhost> | -I <IP-address>) [-u <uri>] [-p <port>] [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>] [-s string] [-r <regex> | -R <case-insensitive regex>] [-P string]
check_http (-h | --help) for detailed help
check_http (-V | --version) for version information

NOTE: One or both of -H and -I must be specified

Options:

-H, --hostname=ADDRESS Host name argument for servers using host headers (virtual host)
-I, --IP-address=ADDRESS IP address or name (use numeric address if possible to bypass DNS lookup).
-e, --expect=STRING String to expect in first (status) line of server response (default: HTTP/1.)
If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)
-s, --string=STRING String to expect in the content
-u, --url=PATH URL to GET or POST (default: /)
-p, --port=INTEGER Port number (default: 80)
-P, --post=STRING URL encoded http POST data
-w, --warning=INTEGER Response time to result in warning status (seconds)
-c, --critical=INTEGER Response time to result in critical status (seconds)
-t, --timeout=INTEGER Seconds before connection times out (default: 10)
-a, --authorization=AUTH_PAIR Username:password on sites with basic authentication
-L, --link=URL Wrap output in HTML link (obsoleted by urlize)
-f, --onredirect=<ok|warning|critical|follow> How to handle redirected pages
-S, --ssl Connect via SSL
-C, --certificate=INTEGER Minimum number of days a certificate has to be valid.
(when this option is used the url is not checked.)
-v, --verbose Show details for command-line debugging (do not use with nagios server)
-h, --help Print detailed help screen
-V, --version Print version information

This plugin can also check whether an SSL enabled web server is able to serve content (optionally within a specified time) or whether the X509 certificate is still valid for the specified number of days.

CHECK CONTENT: check_http -w 5 -c 10 --ssl www.debian.org

When the 'www.debian.org' server returns its content within 5 seconds, a STATE_OK will be returned. When the server returns its content but exceeds the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,a STATE_CRITICAL will be returned.

CHECK CERTIFICATE: check_http www.debian.org -C 14

When the certificate of 'www.debian.org' is valid for more than 14 days, a STATE_OK is returned. When the certificate is still valid, but for less than 14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when the certificate is expired.

Top

check_imap

This plugin tests IMAP connections with the specified host.

Usage:

check_imap -H host -p port [-w warn_time] [-c crit_time] [-s send] [-e expect] [-W wait] [-t to_sec] [-v]

Options:

-H, --hostname=ADDRESS Host name argument for servers using host headers (use numeric
address if possible to bypass DNS lookup).
-p, --port=INTEGER Port number
-s, --send=STRING String to send to the server
-e, --expect=STRING String to expect in server response -W, --wait=INTEGER Seconds to wait between sending string and polling for response -w, --warning=DOUBLE Response time to result in warning status (seconds)
-c, --critical=DOUBLE Response time to result in critical status (seconds)
-t, --timeout=INTEGER Seconds before connection times out (default: 10)
-v Show details for command-line debugging (do not use with nagios server)
-h, --help Print detailed help screen
-V, --version Print version information

Top

check_ircd

Perl Check IRCD plugin for Nagios

Usage:

check_ircd -H <host> [-w <warn>] [-c <crit>] [-p <port>]

Options:

-H, --hostname=HOST Name or IP address of host to check
-w, --warning=INTEGER Number of connected users which generates a warning state (Default: 50)
-c, --critical=INTEGER Number of connected users which generates a critical state (Default: 100)
-p, --port=INTEGER Port that the ircd daemon is running on <host> (Default: 6667)
-v, --verbose Print extra debugging information

Top

check_load

This plugin tests the current system load average.

Usage:

check_load -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15
check_load --version
check_load --help

Options:

-w, --warning=WLOAD1,WLOAD5,WLOAD15 Exit with WARNING status if load average exceeds WLOADn
-c, --critical=CLOAD1,CLOAD5,CLOAD15 Exit with CRITICAL status if load average exceed CLOADn
-h, --help Print detailed help screen
-V, --version Print version information

the load average format is the same used by "uptime" and "w"

Top

check_log

Usage: check_log -F logfile -O oldlog -q query
Usage: check_log --help
Usage: check_log --version

Log file pattern detector plugin for Nagios

Top

check_mailq

Usage:

check_mailq [-w <warn>] [-c <crit>] [-t <timeout>] [-v verbose]

Checks the number of messages in the mail queue Feedback/patches to support non-sendmail mailqueue welcome

Options:

-w (--warning) = Min. number of messages in queue to generate warning
-c (--critical) = Min. number of messages in queu to generate critical alert ( w < c )
-t (--timeout) = Plugin timeout in seconds (default = 15)
-h (--help)
-V (--version)
-v (--verbose) = deebugging output

Top

check_mrtg

This plugin will check either the average or maximum value of one of the
two variables recorded in an MRTG log file.

Usage:

check_mrtg -F log_file -a <AVG | MAX> -v variable -w warning -c critical [-l label] [-u units] [-e expire_minutes] [-t timeout] [-v]
check_mrtg (-h | --help) for detailed help
check_mrtg (-V | --version) for version information

Options:

-F, --logfile=FILE The MRTG log file containing the data you want to monitor
-e, --expires=MINUTES Minutes before MRTG data is considered to be too old
-a, --aggregation=AVG|MAX Should we check average or maximum values?
-v, --variable=INTEGER Which variable set should we inspect? 1 or 2?
-w, --warning=INTEGER Threshold value for data to result in WARNING status
-c, --critical=INTEGER Threshold value for data to result in CRITICAL status
-l, --label=STRING Type label for data (Examples: Conns, "Processor Load", In, Out)
-u, --units=STRING Option units label for data (Example: Packets/Sec, Errors/Sec,
"Bytes Per Second", "% Utilization")
-h, --help Print detailed help screen
-V, --version Print version information

If the value exceeds the <vwl> threshold, a WARNING status is returned. If the value exceeds the <vcl> threshold, a CRITICAL status is returned. If the data in the log file is older than <expire_minutes> old, a WARNING status is returned and a warning message is printed.

This plugin is useful for monitoring MRTG data that does not correspond to bandwidth usage. (Use the check_mrtgtraf plugin for monitoring bandwidth).It can be used to monitor any kind of data that MRTG is monitoring - errors,packets/sec, etc. I use MRTG in conjuction with the Novell NLM that allows
me to track processor utilization, user connections, drive space, etc and this plugin works well for monitoring that kind of data as well.

Notes:- This plugin only monitors one of the two variables stored in the MRTG log file. If you want to monitor both values you will have to define two commands with different values for the <variable> argument. Of course,you can always hack the code to make this plugin work for you.

- MRTG stands for the Multi Router Traffic Grapher. It can be downloaded from here

Top

check_mrtgtraf

This plugin tests the UPS service on the specified host.

Usage:

check_mrtgtraf -F <log_file> -a <AVG | MAX> -v <variable> -w <warning_pair> -c <critical_pair>
[-e expire_minutes] [-t timeout] [-v]
check_mrtgtraf --help
check_mrtgtraf --version

Options:

-F, --filename=STRING File to read log from
-e, --expires=INTEGER  Minutes after which log expires
-a, --aggregation=(AVG|MAX) Test average or maximum -w, --warning
Warning threshold pair "<incoming>,<outgoing>"
-c, --critical Critical threshold pair "<incoming>,<outgoing>"
-h, --help Print detailed help screen
-V, --version Print version information

Top

check_nagios

This plugin attempts to check the status of the Nagios process on the local machine. The plugin will check to make sure the Nagios status log is no older than the number of minutes specified by the <expire_minutes> option. It also uses the /bin/ps command to check for a process matching whatever you specify
by the <process_string> argument.

Usage:

check_nagios -F <status log file> -e <expire_minutes> -C <process_string>

Options:

-F, --filename=FILE Name of the log file to check
-e, --expires=INTEGER Seconds aging afterwhich logfile is condsidered stale
-C, --command=STRING Command to search for in process table
-h, --help Print this help screen
-V, --version Print version information

Example:

./check_nagios -H /usr/local/nagios/var/status.log -e 5 -C /usr/local/nagios/bin/nagios

Top

check_nntp

This plugin tests NNTP connections with the specified host.

Usage:

check_nntp -H host -p port [-w warn_time] [-c crit_time] [-s send] [-e expect] [-W wait] [-t to_sec] [-v]

Options:

-H, --hostname=ADDRESS Host name argument for servers using host headers (use numeric address if possible to bypass DNS lookup).
-p, --port=INTEGER Port number
-s, --send=STRING String to send to the server
-e, --expect=STRING String to expect in server response -W, --wait=INTEGER Seconds to wait between sending string and polling for response
-w, --warning=DOUBLE Response time to result in warning status (seconds)
-c, --critical=DOUBLE Response time to result in critical status (seconds)
-t, --timeout=INTEGER Seconds before connection times out (default: 10)
-v Show details for command-line debugging (do not use with nagios server)
-h, --help Print detailed help screen
-V, --version Print version information

Top

check_ntp

Usage:

check_ntp -H <host> [-w <warn>] [-c <crit>] [-v verbose]

Options:

<warn> = Clock offset in seconds at which a warning message will be generated.Defaults to 60.
<crit> = Clock offset in seconds at which a critical message will be generated.Defaults to 120.

The same warning and critical values are used to check against the dispersion column of ntpdc/xntpdc for the host being queried.

Top

check_nwstat

This plugin attempts to contact the MRTGEXT NLM running on a Novell server to gather the requested system information.

Usage:

check_nwstat -H host [-v variable] [-w warning] [-c critical] [-p port] [-t timeout]
check_nwstat (-h | --help) for detailed help
check_nwstat (-V | --version) for version information

Options:

-H, --hostname=HOST Name of the host to check
-v, --variable=STRING Variable to check. Valid variables include:
LOAD1 = 1 minute average CPU load
LOAD5 = 5 minute average CPU load
LOAD15 = 15 minute average CPU load
CONNS = number of currently licensed connections
VPF<vol> = percent free space on volume <vol>
VKF<vol> = KB of free space on volume <vol>
LTCH = percent long term cache hits
CBUFF = current number of cache buffers
CDBUFF = current number of dirty cache buffers
LRUM = LRU sitting time in minutes
DSDB = check to see if DS Database is open
LOGINS = check to see if logins are enabled
UPRB = used packet receive buffers
PUPRB = percent (of max) used packet receive buffers
SAPENTRIES = number of entries in the SAP table
SAPENTRIES<n> = number of entries in the SAP table for SAP type <n>
OFILES = number of open files
VPP<vol> = percent purgeable space on volume <vol>
VKP<vol> = KB of purgeable space on volume <vol>
VPNP<vol> = percent not yet purgeable space on volume <vol>
VKNP<vol> = KB of not yet purgeable space on volume <vol>
ABENDS = number of abended threads (NW 5.x only)
CSPROCS = number of current service processes (NW 5.x only)
-w, --warning=INTEGER Threshold which will result in a warning status
-c, --critical=INTEGER Threshold which will result in a critical status
-p, --port=INTEGER Optional port number (default: 9999)
-t, --timeout=INTEGER Seconds before connection attempt times out (default: 10)
-o, --osversion Include server version string in results
-h, --help Print this help screen
-V, --version Print version information

Notes:
- This plugin requres that the MRTGEXT.NLM file from James Drews' MRTG extension for NetWare be loaded on the Novell servers you wish to check.(available from http://www.engr.wisc.edu/~drews/mrtg/)
- Values for critical thresholds should be lower than warning thresholds when the following variables are checked: VPF, VKF, LTCH, CBUFF, and LRUM.

Top

check_overcr

This plugin attempts to contact the Over-CR collector daemon running on the remote UNIX server in order to gather the requested system information. This plugin requres that Eric Molitors' Over-CR collector daemon be running on the remote server. Over-CR can be downloaded from http://www.molitor.org/overcr
(This plugin was tested with version 0.99.53 of the Over-CR collector)

Usage:

check_overcr -H host [-p port] [-v variable] [-w warning] [-c critical] [-t timeout]

Options:

-H, --hostname=HOST Name of the host to check
-p, --port=INTEGER Optional port number (default: 2000)
-v, --variable=STRING Variable to check. Valid variables include:
LOAD1 = 1 minute average CPU load
LOAD5 = 5 minute average CPU load
LOAD15 = 15 minute average CPU load
DPU<filesys> = percent used disk space on filesystem <filesys>
PROC<process> = number of running processes with name <process>
NET<port> = number of active connections on TCP port <port>
UPTIME = system uptime in seconds
-w, --warning=INTEGER Threshold which will result in a warning status
-c, --critical=INTEGER Threshold which will result in a critical status
-t, --timeout=INTEGER Seconds before connection attempt times out (default: 10)
-h, --help Print this help screen
-V, --version Print version information

Notes:
- For the available options, the critical threshold value should always be higher than the warning threshold value, EXCEPT with the uptime variable (i.e. lower uptimes are worse).

Top

check_ping

Use ping to check connection statistics for a remote host.

Usage:

check_ping -H <host_address> -w <wrta>,<wpl>%% -c <crta>,<cpl>%% [-p packets] [-t timeout] [-L]
check_ping (-h | --help) for detailed help
check_ping (-V | --version) for version information

Options:

-H, --hostname=HOST host to ping
-w, --warning=THRESHOLD warning threshold pair
-c, --critical=THRESHOLD critical threshold pair
-p, --packets=INTEGER number of ICMP ECHO packets to send (Default: 5)
-t, --timeout=INTEGER optional specified timeout in second (Default: 10)
-L, --link show HTML in the plugin output (obsoleted by urlize)
THRESHOLD is <rta>,<pl>% where <rta> is the round trip average travel time (ms) which triggers a WARNING or CRITICAL state, and <pl> is the percentage of packet loss to trigger an alarm state.

This plugin uses the ping command to probe the specified host for packet loss (percentage) and round trip average (milliseconds). It can produce HTML output linking to a traceroute CGI contributed by Ian Cass. The CGI can be found in the contrib area of the downloads section at http://www.nagios.org/

Top

check_pop

This plugin tests POP connections with the specified host.

Usage:

check_pop -H host -p port [-w warn_time] [-c crit_time] [-s send] [-e expect] [-W wait] [-t to_sec] [-v]

Options:

-H, --hostname=ADDRESS Host name argument for servers using host headers (use numeric address if possible to bypass DNS lookup).
-p, --port=INTEGER Port number
-s, --send=STRING String to send to the server
-e, --expect=STRING String to expect in server response -W, --wait=INTEGER Seconds to wait between sending string and polling for response
-w, --warning=DOUBLE Response time to result in warning status (seconds)
-c, --critical=DOUBLE Response time to result in critical status (seconds)
-t, --timeout=INTEGER Seconds before connection times out (default: 10)
-v Show details for command-line debugging (do not use with nagios server)
-h, --help Print detailed help screen
-V, --version Print version information

Top

check_procs

Check the number of currently running processes and generates WARNING or CRITICAL states if the process count is outside the specified threshold ranges. The process count can be filtered by process owner, parent process PID, current state (e.g., 'Z'), or may be the total number of running processes

Usage:

check_procs -w <range> -c <range> [-s state] [-p ppid] [-u user] [-a argument-array] [-C command]
check_procs --version
check_procs --help

Required Arguments:

-w, --warning=RANGE generate warning state if process count is outside this range
-c, --critical=RANGE generate critical state if process count is outside this range

Optional Filters:

-s, --state=STATUSFLAGS Only scan for processes that have, in the output of `ps`, one or more of the status flags you specify (for example R, Z, S, RS,RSZDT, plus others based on the output of your 'ps' command).
-p, --ppid=PPID Only scan for children of the parent process ID indicated.
-u, --user=USER Only scan for proceses with user name or ID indicated.
-a, --argument-array=STRING Only scan for ARGS that match up to the length of the given STRING
-C, --command=COMMAND Only scan for exact matches to the named COMMAND.

RANGEs are specified 'min:max' or 'min:' or ':max' (or 'max'). If specified 'max:min', a warning status will be generated if the count is inside the specified range

Top

check_real

This plugin tests the REAL service on the specified host.

Usage:

check_real -H host [-e expect] [-p port] [-w warn] [-c crit] [-t timeout] [-v]
check_real --help
check_real --version

Options:

-H, --hostname=STRING or IPADDRESS Check this server on the indicated host
-I, --IPaddress=STRING or IPADDRESS Check server at this host address
-p, --port=INTEGER Make connection on the indicated port (default: 554)
-u, --url=STRING Connect to this url
-e, --expect=STRING String to expect in first line of server response (default: RTSP/1.)
-w, --warning=INTEGER Seconds necessary to result in a warning status
-c, --critical=INTEGER Seconds necessary to result in a critical status
-t, --timeout=INTEGER Seconds before connection attempt times out (default: 10)
-v, --verbose Print extra information (command-line use only)
-h, --help Print detailed help screen
-V, --version Print version information

Top

check_rpc

Check if a rpc service is registered and running using rpcinfo -H host -C rpc_command

Usage:

check_rpc -H host -C rpc_command [-p port] [-c program_version] [-u|-t] [-v]

Options:

check_rpc [-h | --help]
check_rpc [-V | --version]

<host> The server providing the rpc service
<rpc_command> The program name (or number).
<program_version> The version you want to check for (one or more)
Should prevent checks of unknown versions being syslogged
e.g. 2,3,6 to check v2, v3, and v6
[-u | -t] Test UDP or TCP
[-v] Verbose
[-v -v] Verbose - will print supported programs and numbers

Top

check_sensors

This plugin checks hardware status using the lm_sensors package.

Top

check_smtp

This plugin test the SMTP service on the specified host.

Usage:

check_smtp -H host [-e expect] [-p port] [-f from addr] [-w warn] [-c crit] [-t timeout] [-v]
check_smtp --help
check_smtp --version

Options:

-H, --hostname=STRING or IPADDRESS Check server on the indicated host
-p, --port=INTEGER Make connection on the indicated port (default: 25)
-e, --expect=STRING String to expect in first line of server response (default: 220)
-f, --from=STRING from address to include in MAIL command (default NULL, Exchange2000 requires one)
-w, --warning=INTEGER Seconds necessary to result in a warning status
-c, --critical=INTEGER Seconds necessary to result in a critical status
-t, --timeout=INTEGER Seconds before connection attempt times out (default: 10)
-v, --verbose Print extra information (command-line use only)
-h, --help Print detailed help screen
-V, --version Print version information

Top

check_ssh

Usage:

check_ssh -t [timeout] -p [port] <host>
check_ssh -V prints version info
check_ssh -h prints more detailed help
by default, port is 22

Top

check_swap

This plugin will check all of the swap partitions and return an error if the the avalable swap space is less than specified.

Usage:

check_swap -w <used_percentage>% -c <used_percentage>%
check_swap -w <bytes_free> -c <bytes_free>
check_swap (-V|--version)
check_swap (-h|--help)

Options:

-w, --warning=INTEGER Exit with WARNING status if less than INTEGER bytes of swap space are free
-w, --warning=PERCENT% Exit with WARNING status if more than PERCENT of swap space has been used
-c, --critical=INTEGER Exit with CRITICAL status if less than INTEGER bytes of swap space are free
-c, --critical=PERCENT% Exit with CRITCAL status if more than PERCENT of swap space has been used
-h, --help Print detailed help screen
-V, --version Print version information

Top

check_tcp

This plugin tests TCP connections with the specified host.

Usage:

check_tcp -H host -p port [-w warn_time] [-c crit_time] [-s send] [-e expect] [-W wait] [-t to_sec] [-v]

Options:

-H, --hostname=ADDRESS Host name argument for servers using host headers (use numeric
address if possible to bypass DNS lookup).
-p, --port=INTEGER Port number
-s, --send=STRING String to send to the server
-e, --expect=STRING String to expect in server response -W, --wait=INTEGER Seconds to wait between sending string and polling for response
-w, --warning=DOUBLE Response time to result in warning status (seconds)
-c, --critical=DOUBLE Response time to result in critical status (seconds)
-t, --timeout=INTEGER Seconds before connection times out (default: 10)
-v Show details for command-line debugging (do not use with nagios server)
-h, --help Print detailed help screen
-V, --version Print version information

Top

check_time

Check time on the specified host.

Usage:

check_time -H <host_address> [-p port] [-w variance] [-c variance] [-W connect_time] [-C connect_time] [-t timeout]
check_time (-h | --help) for detailed help
check_time (-V | --version) for version information

Options:

-H, --hostname=ADDRESS Host name argument for servers using host headers (use numeric
address if possible to bypass DNS lookup).
-w, --warning-variance=INTEGER Time difference (sec.) necessary to result in a warning status
-c, --critical-variance=INTEGER Time difference (sec.) necessary to result in a critical status
-W, --warning-connect=INTEGER Response time (sec.) necessary to result in warning status
-C, --critical-connect=INTEGER Response time (sec.) necessary to result in critical status
-t, --timeout=INTEGER Seconds before connection times out (default: 10)
-p, --port=INTEGER Port number (default: 37)
-h, --help Print detailed help screen
-V, --version Print version information

Top

check_udp

This plugin tests an UDP connection with the specified host.

Usage:

check_udp -H <host_address> [-p port] [-w warn_time] [-c crit_time] [-e expect] [-s send] [-t to_sec] [-v]

Options:

-H, --hostname=ADDRESS Host name argument for servers using host headers (use numeric
address if possible to bypass DNS lookup).
-p, --port=INTEGER Port number
-e, --expect=STRING <optional> String to expect in first line of server response
-s, --send=STRING <optional> String to send to the server when initiating the connection
-w, --warning=INTEGER <optional> Response time to result in warning status (seconds)
-c, --critical=INTEGER <optional> Response time to result in critical status (seconds)
-t, --timeout=INTEGER <optional> Seconds before connection times out (default: 10)
-v, --verbose <optional> Show details for command-line debugging (do not use with nagios server)
-h, --help Print detailed help screen and exit
-V, --version Print version information and exit

Top

check_ups

This plugin tests the UPS service on the specified host. Network UPS Tools from www.networkupstools.org must be running for this plugin to work.

Usage:

check_ups -H host -u ups [-p port] [-v variable] [-w warn_value] [-c crit_value] [-to to_sec] [-T]

Options:

-h, --help
Print detailed help screen
-V, --version
Print version information
--extra-opts=[section][@file]
Read options from an ini file. See
https://www.monitoring-plugins.org/doc/extra-opts.html
for usage and examples.
-H, --hostname=ADDRESS
Host name, IP Address, or unix socket (must be an absolute path)
-p, --port=INTEGER
Port number (default: 3493)
-u, --ups=STRING
Name of UPS
-T, --temperature
Output of temperatures in Celsius
-v, --variable=STRING
Valid values for STRING are LINE, TEMP, BATTPCT or LOADPCT
-w, --warning=DOUBLE
Response time to result in warning status (seconds)
-c, --critical=DOUBLE
Response time to result in critical status (seconds)
-t, --timeout=INTEGER
Seconds before connection times out (default: 10)

This plugin attempts to determine the status of a UPS (Uninterruptible Power Supply) on a local or remote host. If the UPS is online or calibrating, the plugin will return an OK state. If the battery is on it will return a WARNING state. If the UPS is off or has a low battery the plugin will return a CRITICAL state.

Notes:
You may also specify a variable to check (such as temperature, utility voltage, battery load, etc.) as well as warning and critical thresholds for the value of that variable. If the remote host has multiple UPS that are being monitored you will have to use the --ups option to specify which UPS to check.

This plugin requires that the UPSD daemon distributed with Russell Kroll's Network UPS Tools be installed on the remote host. If you do not have the package installed on your system, you can download it from http://www.networkupstools.org

Top

check_users

This plugin checks the number of users currently logged in on the local system and generates an error if the number exceeds the thresholds specified.

Usage:

check_users -w <users> -c <users>

Options:

-w, --warning=INTEGER Set WARNING status if more than INTEGER users are logged in
-c, --critical=INTEGER Set CRITICAL status if more than INTEGER users are logged in
-h, --help Print detailed help screen
-V, --version Print version information

Top

check_vsz

This plugin checks the image size of a running program and returns an error if the number is above either of the thresholds given.

Usage:

check_vsz -w <wsize> -c <csize> [-C command]
check_vsz --help
check_vsz --version

Options:

-h, --help Print detailed help
-V, --version Print version numbers and license information
-w, --warning=INTEGER Program image size necessary to cause a WARNING state
-c, --critical=INTEGER Program image size necessary to cause a CRITICAL state
-C, --command=STRING Program to search for [optional]

Top

check_wave

Usage:

check_wave -H <host> [-w <warn>] [-c <crit>]

<warn> = Signal strength at which a warning message will be generated.
<crit> = Signal strength at which a critical message will be generated.




                     **************************************************


 
Need personal assistance on Nagios? Please contact me at

immukesh72@gmail.com

at very nominal charges

Tuesday 10 May 2016

Python Script to read and write a csv file

CSV stands for "comma separated values" is the most common import and export format for spreadsheets and databases. Python provides the csv module in which reader objects allow you to read the csv file and writer object to write a csv file. Programmers can also read and write data in dictionary form using the DictReader and DictWriter classes.

Note : Python2.7 csv module doesn’t support Unicode input. Also, there are currently some issues regarding ASCII NUL characters. Accordingly, all input should be UTF-8 or printable ASCII to be safe.

Python Script to write testFile.csv :

Writing csv file is easy first you need to import csv module in your program and then csv.writer() will create a writer object and then csv.writer() object will create the empty csv file as per given arguments and later you can use writerow() to write the comma separated values.Look at the following program.

import csv

# Creating a file object in appending mode
f=open('myFile.csv','ab')try:
    # Creating the writer object and myFile.csv
    csvWriter = csv.writer(f, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
 
    # Writing the csv header
    csvWriter.writerow(['SNO','Employee','Salary'])
    
    # Writing the content into csv file
    csvWriter.writerow([1,"Jon Baker","20,000"])
    csvWriter.writerow([2,"Abhishek","60,000"])
    csvWriter.writerow([3,"Dinesh Kumar","28,000"])
    csvWriter.writerow([4,"Anita","22,000"])
    csvWriter.writerow([5,"Ajay Singh","26,000"])
finally:
    f.close()


Run the above program and confirm the myFile.csv has been generated with its contents.

Quoting:

There are four different quoting options, defined as constants in the csv module.

QUOTE_ALL
Quote everything, regardless of type.
QUOTE_MINIMAL
Quote fields with special characters (anything that would confuse a parser configured with the same dialect and options). This is the default
QUOTE_NONNUMERIC
Quote all fields that are not integers or floats. When used with the reader, input fields that are not quoted are converted to floats.
QUOTE_NONE
Do not quote anything on output. When used with the reader, quote characters are included in the field values (normally, they are treated as delimiters and stripped).

Python Script to read testFile.csv :

For reading the csv file, first create the file object of file for which you want to read in read mode. Use reader() to create an object for reading data from a CSV file. The reader can be used as an iterator to process the rows of the file in order. Look at below program:

import csv

# Creating a file object in appending mode
f=open('myFile.csv','rb')

try:
    csvReader=csv.reader(f)
    for row in csvReader:
        print row
finally:
    f.close()
   
The output you will get something like this.
['SNO', 'Employee', 'Salary']
['1', 'Jon Baker', '20,000']
['2', 'Abhishek', '60,000']
['3', 'Dinesh Kumar', '28,000']
['4', 'Anita', '22,000']
['5', 'Ajay Singh', '26,000']


If you want to read a particular column then provide the index while iterating the csvReader list. Look at the below example in which i am reading just second column of CSV file.

import csv

# Creating a file object in read mode
f=open('myFile.csv','rb')

try:
    csvReader=csv.reader(f)
    for row in csvReader:
        print row[1]
finally:
    f.close()
   
The output will be something like a below:

Employee
Jon Baker
Abhishek
Dinesh Kumar
Anita
Ajay Singh


Note : Open method have 2 argument open(filename,mode) , We have different following kind of modes:
   : When the file will only be read
: When the file only writing (an existing file with the same name will be erased)
a   : Opens the file for appending; any data written to the file is automatically added to the end
r+ : Opens the file for both reading and writing. The mode argument is optional; 'r' will be assumed if it’s omitted.
On Windows, 'b' appended to the mode opens the file in binary mode, so there are also modes like 'rb', 'wb', and 'r+b'. Python on Windows makes a distinction between text and binary files

                  

                                ***************************************
Related Posts Plugin for WordPress, Blogger...