summaryrefslogtreecommitdiffstats
path: root/contrib/check_sockets.pl
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/check_sockets.pl')
-rw-r--r--contrib/check_sockets.pl145
1 files changed, 0 insertions, 145 deletions
diff --git a/contrib/check_sockets.pl b/contrib/check_sockets.pl
deleted file mode 100644
index b8ae24a2..00000000
--- a/contrib/check_sockets.pl
+++ /dev/null
@@ -1,145 +0,0 @@
1#! /usr/bin/perl
2# ------------------------------------------------------------------------------
3# File Name: check_sockets.pl
4# Author: Richard Mayhew - South Africa
5# Date: 2000/07/11
6# Version: 1.0
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
14# changes :)
15# Some code taken from Charlie Cook (check_disk.pl)
16# License GPL
17#
18# ------------------------------------------------------------------------------
19# Date Author Reason
20# ---- ------ ------
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'
26#
27# ------------------------------------------------------------------------------
28
29# -----------------------------------------------------------------[ Require ]--
30require 5.004;
31# --------------------------------------------------------------------[ Uses ]--
32use Socket;
33use strict;
34# --------------------------------------------------------------[ Enviroment ]--
35$ENV{'PATH'}='/bin:/sbin:/usr/bin:/usr/sbin';
36$ENV{BASH_ENV} = "";
37# ------------------------------------------------------------------[ Global ]--
38my $TIMEOUT = 20;
39my %ERRORS = (
40 'UNKNOWN', '-1',
41 'OK', '0',
42 'WARNING', '1',
43 'CRITICAL', '2');
44# --------------------------------------------------------------[ connection ]--
45sub connection
46{
47 my ($in_total,$in_warn,$in_crit,$in_high) = @_;
48 my $state;
49 my $answer;
50
51 $in_total =~ s/\ //g;
52 if ($in_total >= 0) {
53
54 if ($in_total > $in_crit) {
55 $state = "CRITICAL";
56 $answer = "Critical Number Of Sockets Connected : $in_total (Limit = $in_crit)\n";
57
58 } elsif ($in_total > $in_warn) {
59 $state = "WARNING";
60 $answer = "Warning Number Of Sockets Connected : $in_total (Limit = $in_warn)\n";
61
62 } else {
63 if ($in_high ne "") {
64 $answer = "Sockets OK - Current Sockets: $in_total : $in_high\n";
65 }
66 if ($in_high eq "") {
67 $answer = "Sockets OK - Current Sockets: $in_total\n";
68 }
69 $state = "OK";
70 }
71
72 } else {
73 $state = "UNKNOWN";
74 $answer = "Something is Really WRONG! Sockets Is A Negative Figure!\n";
75 }
76
77 print $answer;
78 exit $ERRORS{$state};
79}
80
81# -------------------------------------------------------------------[ usage ]--
82sub usage
83{
84 print "Minimum arguments not supplied!\n";
85 print "\n";
86 print "Perl Check Sockets plugin for Nagios\n";
87 print "Copyright (c) 2000 Richard Mayhew\n";
88 print "\n";
89 print "Usage: check_sockets.pl <type> <warn> <crit>\n";
90 print "\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"};
95
96}
97
98# ====================================================================[ MAIN ]==
99MAIN:
100{
101 my $type = shift || &usage;
102 my $warn = shift || 256;
103 my $crit = shift || 512;
104 my $data;
105 my @data;
106 my $line;
107 my $data1;
108 my $data2;
109 my $data3;
110 my $junk;
111 my $total1;
112 my $total2;
113 $type = uc $type;
114 if ($type eq "TOTAL") {
115 $type = "sockets";
116 }
117
118 # Just in case of problems, let's not hang Nagios
119 $SIG{'ALRM'} = sub {
120 print "Somthing is Taking a Long Time, Increase Your TIMEOUT (Currently Set At $TIMEOUT Seconds)\n";
121 exit $ERRORS{"UNKNOWN"};
122 };
123
124 $data = `/bin/cat /proc/net/sockstat`;
125 @data = split("\n",$data);
126 alarm($TIMEOUT);
127 my $output = "";
128 my $high;
129
130
131 foreach $line (@data) {
132 if ($line =~ /$type/) {
133 ($data1,$data2,$data3) = split(" ",$line,3);
134
135 if ($data3 =~ /highest/){
136 ($total1,$junk,$total2) = split(" ",$data3,3);
137 $output = $total1;
138 $high = $total2;
139 }
140 else {$output = $data3;}
141 alarm(0);
142 connection($output,$warn,$crit,$high);
143 }
144 }
145}