summaryrefslogtreecommitdiffstats
path: root/web/attachments/242023-check_ifstatus.patch
blob: 76f490dd178d25aadf1f517ed96752a8939c0dec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
1a2,12
> # vim:foldmethod=syntax:tabstop=4:shiftwidth=4
> #
> # matthew.martin, Tuesday August 14, 2007
> # Problems with check_ifstatus.pl
> #	1) "No response from remote host" should be unknown, not critical, right?
> #	2) Serial link "dormant" should be critical, not okay
> #	3) dormant, excluded and unused interfaces are not correctly counted
> #	4) default exclusions were broken, fix that and add a couple default exclusions
> #	5) made the formatting in this file more consistent
> #
> # check_ifstatus.pl - nagios plugin
3,4d13
< # check_ifstatus.pl - nagios plugin 
< # 
29c38
< # 
---
> #
36c45
< use lib "/opt/csw/libexec/nagios-plugins" ;
---
> use lib "/opt/csw/libexec/nagios-plugins";
49d57
< 
94c102
< my %excluded ;
---
> my %excluded;
97,100d104
< 
< 
< 
< 
103,104c107,108
<      print ("ERROR: No snmp response from $hostname (alarm timeout)\n");
<      exit $ERRORS{"UNKNOWN"};
---
> 	print ("ERROR: No snmp response from $hostname (alarm timeout)\n");
> 	exit $ERRORS{"UNKNOWN"};
107,108c111
< 
< #Option checking
---
> # Option checking
111,112c114
< if ($status != 0)
< {
---
> if ($status != 0) {
117d118
< 
127,129d127
< 
< 
< 
131,135c129,135
< 
<    if (!defined($response = $session->get_table($snmpoid))) {
<       $answer=$session->error;
<       $session->close;
<       $state = 'CRITICAL';
---
> 	if (!defined($response = $session->get_table($snmpoid))) {
> 		$answer=$session->error;
> 		$session->close;
> 		# matthew.martin. Tuesday August 14, 2007
> 		# I think a SNMP error should give UNKNOWN, not CRITICAL
> 		#$state = 'CRITICAL';
> 		$state = 'UNKNOWN';
138c138
< 			}else{
---
> 			} else {
141,142c141,142
<       exit $ERRORS{$state};
<    }
---
> 	exit $ERRORS{$state};
> 	}
144,148c144,148
<    foreach $snmpkey (keys %{$response}) {
<       $snmpkey =~ /.*\.(\d+)$/;
<       $key = $1;
<       $ifStatus{$key}{$snmpoid} = $response->{$snmpkey};
<    }
---
> 	foreach $snmpkey (keys %{$response}) {
> 		$snmpkey =~ /.*\.(\d+)$/;
> 		$key = $1;
> 		$ifStatus{$key}{$snmpoid} = $response->{$snmpkey};
> 	}
151d150
< 
155a155,156
> # matthew.martin. This script cannot tell that specific logical interfaces are
> # associated with their phys IF so it checks them all.
158c159,160
< 	# skip unused interfaces
---
> 	# Skip interfaces flagged with -u (--unused_ports)
> 	# "A comma separated list of ifIndex values that should be excluded"
160,163c162,166
< 		# check only if interface is administratively up
<     if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) {
<     
< 			# check only if interface type is not listed in %excluded
---
> 
> 		# Further checking only if interface is administratively up
> 		if ($ifStatus{$key}{$snmpIfAdminStatus} == 1 ) {
> 
> 			# Check only if interface type is not listed in %excluded
170,172c173,175
<                                 $ifStatus{$key}{$snmpIfName},
< 																$ifStatus{$key}{$snmpIfAlias});
< 								}else{
---
> 															$ifStatus{$key}{$snmpIfName},
> 															$ifStatus{$key}{$snmpIfAlias});
> 								} else {
174c177
< 																$ifStatus{$key}{$snmpIfDescr});
---
> 															$ifStatus{$key}{$snmpIfDescr});
178c181,182
< 			}else{
---
> 			# matthew.martin Interface is listed in %excluded
> 			} else {
181c185,187
< 		
---
> 		# matthew.martin If not administratively up, mark as unused.
> 		} elsif ($ifStatus{$key}{$snmpIfAdminStatus} == 2 ) {
> 			$ifunused++;
183,184c189,195
< 	}else{
< 		$ifunused++;
---
> 	} else {
> 		# matthew.martin. Original line:
> 		# $ifunused++;
> 		# actually matches the flag 
> 		# -u (--unused_ports) A comma separated list of ifIndex values that should be excluded
> 		# They should be marked as excluded, not unused.
> 		$ifexclude++;
188,208c199,224
<    if ($ifdown > 0) {
<       $state = 'CRITICAL';
<       $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d, unused: %d<BR>",
<                         $hostname,
< 			$ifup,
< 			$ifdown,
< 			$ifdormant,
< 			$ifexclude,
< 			$ifunused);
<       $answer = $answer . $ifmessage . "\n";
<    }
<    else {
<       $state = 'OK';
<       $answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d, unused: %d",
<                         $hostname,
< 			$ifup,
< 			$ifdown,
< 			$ifdormant,
< 			$ifexclude,
< 			$ifunused);
<    }
---
> # matthew.martin
> # The original has dormant serial interfaces return status of "OK".
> # A dormant serial connection should be CRITICAL, right?
> # I changed the following line to address this:
> #if ($ifdown > 0) {
> if (($ifdown > 0) || ($ifdormant > 0)) {
> 	$state = 'CRITICAL';
> 	$answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d, unused: %d<BR>",
> 		$hostname,
> 		$ifup,
> 		$ifdown,
> 		$ifdormant,
> 		$ifexclude,
> 		$ifunused);
> 	$answer = $answer . $ifmessage . "\n";
> } else {
> 	$state = 'OK';
> 	$answer = sprintf("host '%s', interfaces up: %d, down: %d, dormant: %d, excluded: %d, unused: %d",
> 		$hostname,
> 		$ifup,
> 		$ifdown,
> 		$ifdormant,
> 		$ifexclude,
> 		$ifunused);
> }
> 
248c264
< 	printf "                     in hex with 0x prefix generated by using	\"snmpkey\" utility\n"; 
---
> 	printf "                     in hex with 0x prefix generated by using	\"snmpkey\" utility\n";
252c268
< 	printf "                     in hex with 0x prefix generated by using	\"snmpkey\" utility\n"; 
---
> 	printf "                     in hex with 0x prefix generated by using	\"snmpkey\" utility\n";
323c339
< 				}else{
---
> 				} else {
326c342
< 					}else{
---
> 					} else {
338c354
< 				}else{
---
> 				} else {
341c357
< 					}else{
---
> 					} else {
370,371d385
< 		}else{
< 			$excluded{23} = 1; # default PPP(23) if empty list - note (AIX seems to think PPP is 22 according to a post)
372a387,391
> 	# matthew.martin, Tuesday August 14, 2007. In the original this else was nested wrong and never matched
> 	} else {
> 		$excluded{23} = 1; # default PPP(23) if empty list - note (AIX seems to think PPP is 22 according to a post)
> 		$excluded{24} = 1; # matthew.martin, Tuesday August 14, 2007, Nokia, ifDescr.6 = loop0c0 Software Loopback Layer -- ifType.6 = softwareLoopback(24) (taken from a Nokia IP330)
> 		$excluded{25} = 1; # matthew.martin, Tuesday August 14, 2007, Nokia, ifDescr.1 = pppoe0 Ethernet Layer -- ifType.1 = eon(25) (from a Nokia IP350)
378c397
< 		foreach $key (@unused_ports) { 
---
> 		foreach $key (@unused_ports) {
392c411
< 	}else{
---
> 	} else {
450c469
< 	}else{
---
> 	} else {