nagios plugins functionality

[root@localhost ~]# locate nagios/plugins |head -n1
/usr/lib64/nagios/plugins

check_swap 

[root@localhost ~]# /usr/lib64/nagios/plugins/check_swap –help
check_swap v2.2.1 (nagios-plugins 2.2.1)
Copyright (c) 2000-2014 Nagios Plugin Development Team
<devel@nagios-plugins.org>

Check swap space on local machine.

Usage:
check_swap [-av] -w % -c %
-w -c

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.nagios-plugins.org/doc/extra-opts.html
for usage and examples.
-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 less than PERCENT of swap space is free
-c, –critical=INTEGER
Exit with CRITICAL status if less than INTEGER bytes of swap space are free
-c, –critical=PERCENT%%
Exit with CRITICAL status if less than PERCENT of swap space is free
-a, –allswaps
Conduct comparisons for all swap partitions, one by one
-v, –verbose
Show details for command-line debugging (Nagios may truncate output)

Notes:
Both INTEGER and PERCENT thresholds can be specified, they are all checked.
On AIX, if -a is specified, uses lsps -a, otherwise uses lsps -s.

Send email to help@nagios-plugins.org if you have questions regarding use
of this software. To submit patches or suggest improvements, send email to
devel@nagios-plugins.org

[root@localhost ~]# /usr/lib64/nagios/plugins/check_swap -w 50
SWAP OK – 100% free (819 MB out of 819 MB) |swap=819MB;0;0;0;819

[root@localhost ~]# echo $?
0

[root@localhost ~]# /usr/lib64/nagios/plugins/check_swap -c 1300
check_swap: Warning free space should be more than critical free space
Usage:
check_swap [-av] -w % -c %
-w -c

[root@localhost ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 839676 620 -1

[root@localhost ~]# swapoff /dev/dm-1

[root@localhost ~]# swapon -s

[root@localhost ~]# /usr/lib64/nagios/plugins/check_swap -w 10
SWAP WARNING – 0% free (0 MB out of 0 MB) – Swap is either disabled, not present, or of zero size. |swap=0MB;0;0;0;0

[root@localhost ~]# echo $?
1

[root@localhost ~]# /usr/lib64/nagios/plugins/check_swap -w 1200 -c 1000
SWAP CRITICAL – 0% free (0 MB out of 0 MB) – Swap is either disabled, not present, or of zero size. |swap=0MB;0;0;0;0

check_ping

[root@localhost ~]# /usr/lib64/nagios/plugins/check_ping -h
check_ping v2.2.1 (nagios-plugins 2.2.1)
Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>
Copyright (c) 2000-2014 Nagios Plugin Development Team
<devel@nagios-plugins.org>

Use ping to check connection statistics for a remote host.

Usage:
check_ping -H -w ,% -c ,%
[-p packets] [-t timeout] [-4|-6]

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.nagios-plugins.org/doc/extra-opts.html
for usage and examples.
-4, –use-ipv4
Use IPv4 connection
-6, –use-ipv6
Use IPv6 connection
-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)
-s, –show-resolution
show name resolution in the plugin output (DNS & IP)
-L, –link
show HTML in the plugin output (obsoleted by urlize)
-t, –timeout=INTEGER:
Seconds before connection times out (default: 10)
Optional “:” can be a state integer (0,1,2,3) or a state STRING

THRESHOLD is ,% where is the round trip average travel
time (ms) which triggers a WARNING or CRITICAL state, and 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/

Send email to help@nagios-plugins.org if you have questions regarding use
of this software. To submit patches or suggest improvements, send email to
devel@nagios-plugins.org

[root@localhost ~]# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=63 time=42.2 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=63 time=41.5 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=63 time=41.3 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=63 time=39.1 ms
^C
— 8.8.8.8 ping statistics —
4 packets transmitted, 4 received, 0% packet loss, time 3006ms
rtt min/avg/max/mdev = 39.186/41.107/42.282/1.185 ms

check if ping for 5sec and if unable to ping report as 5% loss, if unable to reach for 10 sec report it as 10% loss
[root@localhost ~]# /usr/lib64/nagios/plugins/check_ping 8.8.8.8 -w 5000.0,5% -c 10000.0,10%
PING OK – Packet loss = 0%, RTA = 53.40 ms|rta=53.398998ms;5000.000000;10000.000000;0.000000 pl=0%;5;10;0

[root@localhost ~]# /usr/lib64/nagios/plugins/check_ping 192.168.122.133 -w 5000.0,5% -c 10000.0,10%
CRITICAL – Host Unreachable (192.168.122.133)

[root@localhost ~]# /usr/lib64/nagios/plugins/check_ping 127.0.0.1 -w 5000.0,5% -c 10000.0,10%
PING OK – Packet loss = 0%, RTA = 0.09 ms|rta=0.094000ms;5000.000000;10000.000000;0.000000 pl=0%;5;10;0

[root@localhost ~]# /usr/lib64/nagios/plugins/check_ping 8.8.8.8 -w 5.0,5% -c 20.0,10%
PING CRITICAL – Packet loss = 0%, RTA = 48.54 ms|rta=48.536999ms;5.000000;20.000000;0.000000 pl=0%;5;10;0

[root@localhost ~]# /usr/lib64/nagios/plugins/check_ping 8.8.8.8 -w 5.0,5% -c 200.0,10%
PING WARNING – Packet loss = 0%, RTA = 48.29 ms|rta=48.291000ms;5.000000;200.000000;0.000000 pl=0%;5;10;0

check_http

[root@localhost ~]# /usr/lib64/nagios/plugins/check_http -h
check_http v2.2.1 (nagios-plugins 2.2.1)
Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>
Copyright (c) 1999-2014 Nagios Plugin Development Team
<devel@nagios-plugins.org>

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 | -I [-u ] [-p ]
[-J ] [-K ]
[-w ] [-c ] [-t ] [-L] [-E] [-a auth]
[-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]
[-e ] [-d string] [-s string] [-l] [-r | -R ]
[-P string] [-m :] [-4|-6] [-N] [-M ]
[-A string] [-k string] [-S ] [–sni] [-C [,]]
[-T ] [-j method]
NOTE: One or both of -H and -I must be specified

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.nagios-plugins.org/doc/extra-opts.html
for usage and examples.
-H, –hostname=ADDRESS
Host name argument for servers using host headers (virtual host)
Append a port to include it in the header (eg: example.com:5000)
-I, –IP-address=ADDRESS
IP address or name (use numeric address if possible to bypass DNS lookup).
-p, –port=INTEGER
Port number (default: 80)
-4, –use-ipv4
Use IPv4 connection
-6, –use-ipv6
Use IPv6 connection
-S, –ssl=VERSION[+]
Connect via SSL. Port defaults to 443. VERSION is optional, and prevents
auto-negotiation (2 = SSLv2, 3 = SSLv3, 1 = TLSv1, 1.1 = TLSv1.1,
1.2 = TLSv1.2). With a ‘+’ suffix, newer versions are also accepted.
–sni
Enable SSL/TLS hostname extension support (SNI)
-C, –certificate=INTEGER[,INTEGER]
Minimum number of days a certificate has to be valid. Port defaults to 443
(when this option is used the URL is not checked.)
-J, –client-cert=FILE
Name of file that contains the client certificate (PEM format)
to be used in establishing the SSL session
-K, –private-key=FILE
Name of file containing the private key (PEM format)
matching the client certificate
-e, –expect=STRING
Comma-delimited list of strings, at least one of them is expected in
the first (status) line of the server response (default: HTTP/1.)
If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)
-d, –header-string=STRING
String to expect in the response headers
-s, –string=STRING
String to expect in the content
-u, –uri=PATH
URI to GET or POST (default: /)
–url=PATH
(deprecated) URL to GET or POST (default: /)
-P, –post=STRING
URL encoded http POST data
-j, –method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT)
Set HTTP method.
-N, –no-body
Don’t wait for document body: stop reading after headers.
(Note that this still does an HTTP GET or POST, not a HEAD.)
-M, –max-age=SECONDS
Warn if document is more than SECONDS old. the number can also be of
the form “10m” for minutes, “10h” for hours, or “10d” for days.
-T, –content-type=STRING
specify Content-Type header media type when POSTing

-l, –linespan
Allow regex to span newlines (must precede -r or -R)
-r, –regex, –ereg=STRING
Search page for regex STRING
-R, –eregi=STRING
Search page for case-insensitive regex STRING
–invert-regex
Return CRITICAL if found, OK if not

-a, –authorization=AUTH_PAIR
Username:password on sites with basic authentication
-b, –proxy-authorization=AUTH_PAIR
Username:password on proxy-servers with basic authentication
-A, –useragent=STRING
String to be sent in http header as “User Agent”
-k, –header=STRING
Any other tags to be sent in http header. Use multiple times for additional headers
-E, –extended-perfdata
Print additional performance data
-L, –link
Wrap output in HTML link (obsoleted by urlize)
-f, –onredirect=<ok|warning|critical|follow|sticky|stickyport>
How to handle redirected pages. sticky is like follow but stick to the
specified IP address. stickyport also ensures port stays the same.
-m, –pagesize=INTEGER<:INTEGER>
Minimum page size required (bytes) : Maximum page size required (bytes)
-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)
Optional “:” can be a state integer (0,1,2,3) or a state STRING
-v, –verbose
Show details for command-line debugging (Nagios may truncate output)

Notes:
This plugin will attempt to open an HTTP connection with the host.
Successful connects return STATE_OK, refusals and timeouts return STATE_CRITICAL
other errors return STATE_UNKNOWN. Successful connects, but incorrect reponse
messages from the host result in STATE_WARNING return values. If you are
checking a virtual server that uses ‘host headers’ you must supply the FQDN
(fully qualified domain name) as the [host_name] argument.
You may also need to give a FQDN or IP address using -I (or –IP-Address).

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.

Please note that this plugin does not check if the presented server
certificate matches the hostname of the server, or if the certificate
has a valid chain of trust to one of the locally installed CAs.

Examples:
CHECK CONTENT: check_http -w 5 -c 10 –ssl -H http://www.verisign.com

When the ‘www.verisign.com’ 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 -H http://www.verisign.com -C 14

When the certificate of ‘www.verisign.com’ 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.

CHECK CERTIFICATE: check_http -H http://www.verisign.com -C 30,14

When the certificate of ‘www.verisign.com’ is valid for more than 30 days,
a STATE_OK is returned. When the certificate is still valid, but for less than
30 days, but more than 14 days, a STATE_WARNING is returned.
A STATE_CRITICAL will be returned when certificate expires in less than 14 days
CHECK SSL WEBSERVER CONTENT VIA PROXY USING HTTP 1.1 CONNECT:

check_http -I 192.168.100.35 -p 80 -u https://www.verisign.com/ -S -j CONNECT -H http://www.verisign.com
all these options are needed: -I -p -u -S(sl) -j CONNECT -H
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.

Send email to help@nagios-plugins.org if you have questions regarding use
of this software. To submit patches or suggest improvements, send email to
devel@nagios-plugins.org

[root@localhost ~]# /usr/lib64/nagios/plugins/check_http -I 127.0.0.1

HTTP WARNING: HTTP/1.1 403 Forbidden – 5179 bytes in 0.001 second response time |time=0.001248s;;;0.000000 size=5179B;;;0

[root@localhost ~]# /usr/lib64/nagios/plugins/check_http -I 8.8.8.8
CRITICAL – Socket timeout

[root@localhost ~]# /usr/lib64/nagios/plugins/check_http -H google.com
HTTP OK: HTTP/1.1 302 Found – 526 bytes in 0.434 second response time |time=0.433613s;;;0.000000 size=526B;;;0

[root@localhost ~]# dig +short google.com
216.58.196.110

[root@localhost ~]# /usr/lib64/nagios/plugins/check_http -I 216.58.196.110
HTTP OK: HTTP/1.0 302 Found – 507 bytes in 0.108 second response time |time=0.108401s;;;0.000000 size=507B;;;0

[root@localhost ~]# /usr/lib64/nagios/plugins/check_http -I localhost
HTTP WARNING: HTTP/1.1 403 Forbidden – 5179 bytes in 0.007 second response time |time=0.006610s;;;0.000000 size=5179B;;;0

 

Leave a comment