2 # ------------------------------------------------------------------------------
3 # File Name: check_sockets.pl
4 # Author: Richard Mayhew - South Africa
7 # Description: This script will check to see how may open sockets
8 # a server has and waron respectivly
9 # Email: netsaint@splash.co.za
10 # ------------------------------------------------------------------------------
11 # Copyright 1999 (c) Richard Mayhew
12 # Credits go to Ethan Galstad for coding Nagios
13 # If any changes are made to this script, please mail me a copy of the
15 # Some code taken from Charlie Cook (check_disk.pl)
18 # ------------------------------------------------------------------------------
21 # 1999/09/20 RM Creation
22 # 1999/09/20 TP Changed script to use strict, more secure by
23 # specifying $ENV variables. The bind command is
24 # still insecure through. Did most of my work
25 # with perl -wT and 'use strict'
27 # ------------------------------------------------------------------------------
29 # -----------------------------------------------------------------[ Require ]--
31 # --------------------------------------------------------------------[ Uses ]--
34 # --------------------------------------------------------------[ Enviroment ]--
35 $ENV{'PATH'}='/bin:/sbin:/usr/bin:/usr/sbin';
37 # ------------------------------------------------------------------[ Global ]--
44 # --------------------------------------------------------------[ connection ]--
47 my ($in_total,$in_warn,$in_crit,$in_high) = @_;
54 if ($in_total > $in_crit) {
56 $answer = "Critical Number Of Sockets Connected : $in_total (Limit = $in_crit)\n";
58 } elsif ($in_total > $in_warn) {
60 $answer = "Warning Number Of Sockets Connected : $in_total (Limit = $in_warn)\n";
64 $answer = "Sockets OK - Current Sockets: $in_total : $in_high\n";
67 $answer = "Sockets OK - Current Sockets: $in_total\n";
74 $answer = "Something is Really WRONG! Sockets Is A Negative Figure!\n";
81 # -------------------------------------------------------------------[ usage ]--
84 print "Minimum arguments not supplied!\n";
86 print "Perl Check Sockets plugin for Nagios\n";
87 print "Copyright (c) 2000 Richard Mayhew\n";
89 print "Usage: check_sockets.pl <type> <warn> <crit>\n";
91 print "<type> = TOTAL, TCP, UDP, RAW.\n";
92 print "<warn> = Number of sockets connected at which a warning message will be generated.[Default = 256]\n";
93 print "<crit> = Number of sockets connected at which a critical message will be generated.[Default = 512]\n";
94 exit $ERRORS{"UNKNOWN"};
98 # ====================================================================[ MAIN ]==
101 my $type = shift || &usage
;
102 my $warn = shift || 256;
103 my $crit = shift || 512;
114 if ($type eq "TOTAL") {
118 # Just in case of problems, let's not hang Nagios
120 print "Somthing is Taking a Long Time, Increase Your TIMEOUT (Currently Set At $TIMEOUT Seconds)\n";
121 exit $ERRORS{"UNKNOWN"};
124 $data = `/bin/cat /proc/net/sockstat`;
125 @data = split("\n",$data);
131 foreach $line (@data) {
132 if ($line =~ /$type/) {
133 ($data1,$data2,$data3) = split(" ",$line,3);
135 if ($data3 =~ /highest/){
136 ($total1,$junk,$total2) = split(" ",$data3,3);
140 else {$output = $data3;}
142 connection
($output,$warn,$crit,$high);