summaryrefslogtreecommitdiffstats
path: root/web/attachments/146722-check_ifoperstatus_cache.diff
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/146722-check_ifoperstatus_cache.diff')
-rw-r--r--web/attachments/146722-check_ifoperstatus_cache.diff245
1 files changed, 245 insertions, 0 deletions
diff --git a/web/attachments/146722-check_ifoperstatus_cache.diff b/web/attachments/146722-check_ifoperstatus_cache.diff
new file mode 100644
index 0000000..b0e2ae9
--- /dev/null
+++ b/web/attachments/146722-check_ifoperstatus_cache.diff
@@ -0,0 +1,245 @@
1*** check_ifoperstatus.orig 2005-08-19 17:45:13.000000000 -0400
2--- check_ifoperstatus 2005-08-23 16:32:12.000000000 -0400
3*************** my $community = "public";
4*** 64,78 ****
5 my $maxmsgsize = 1472 ; # Net::SNMP default is 1472
6 my ($seclevel, $authproto, $secname, $authpass, $privpass, $auth, $priv, $context);
7 my $port = 161;
8- my @snmpoids;
9 my $sysUptime = '1.3.6.1.2.1.1.3.0';
10 my $snmpIfDescr = '1.3.6.1.2.1.2.2.1.2';
11 my $snmpIfAdminStatus = '1.3.6.1.2.1.2.2.1.7';
12 my $snmpIfOperStatus = '1.3.6.1.2.1.2.2.1.8';
13 my $snmpIfName = '1.3.6.1.2.1.31.1.1.1.1';
14 my $snmpIfLastChange = '1.3.6.1.2.1.2.2.1.9';
15 my $snmpIfAlias = '1.3.6.1.2.1.31.1.1.1.18';
16 my $snmpLocIfDescr = '1.3.6.1.4.1.9.2.2.1.1.28';
17 my $hostname;
18 my $ifName;
19 my $session;
20--- 64,84 ----
21 my $maxmsgsize = 1472 ; # Net::SNMP default is 1472
22 my ($seclevel, $authproto, $secname, $authpass, $privpass, $auth, $priv, $context);
23 my $port = 161;
24 my $sysUptime = '1.3.6.1.2.1.1.3.0';
25 my $snmpIfDescr = '1.3.6.1.2.1.2.2.1.2';
26+ my $snmpIfDescrOid = $snmpIfDescr;
27 my $snmpIfAdminStatus = '1.3.6.1.2.1.2.2.1.7';
28+ my $snmpIfAdminStatusOid = $snmpIfAdminStatus;
29 my $snmpIfOperStatus = '1.3.6.1.2.1.2.2.1.8';
30+ my $snmpIfOperStatusOid = $snmpIfOperStatus;
31 my $snmpIfName = '1.3.6.1.2.1.31.1.1.1.1';
32+ my $snmpIfNameOid = $snmpIfName;
33 my $snmpIfLastChange = '1.3.6.1.2.1.2.2.1.9';
34+ my $snmpIfLastChangeOid = $snmpIfLastChange;
35 my $snmpIfAlias = '1.3.6.1.2.1.31.1.1.1.18';
36+ my $snmpIfAliasOid = $snmpIfAlias;
37 my $snmpLocIfDescr = '1.3.6.1.4.1.9.2.2.1.1.28';
38+ my $snmpLocIfDescrOid = $snmpLocIfDescr;
39 my $hostname;
40 my $ifName;
41 my $session;
42*************** my $lastc;
43*** 88,93 ****
44--- 94,101 ----
45 my $dormantWarn;
46 my $adminWarn;
47 my $name;
48+ my $cacheFileChecked = 0;
49+ my $cacheFileName = '/tmp/interface_cache.db';
50
51 ### Validate Arguments
52
53*************** alarm($timeout);
54*** 106,114 ****
55 ## map ifdescr to ifindex - should look at being able to cache this value
56
57 if (defined $ifdescr) {
58- # escape "/" in ifdescr - very common in the Cisco world
59- $ifdescr =~ s/\//\\\//g;
60-
61 $status=fetch_ifdescr(); # if using on device with large number of interfaces
62 # recommend use of SNMP v2 (get-bulk)
63 if ($status==0) {
64--- 114,119 ----
65*************** if (defined $ifdescr) {
66*** 122,155 ****
67
68 ## Main function
69
70! $snmpIfAdminStatus = $snmpIfAdminStatus . "." . $snmpkey;
71! $snmpIfOperStatus = $snmpIfOperStatus . "." . $snmpkey;
72! $snmpIfDescr = $snmpIfDescr . "." . $snmpkey;
73! $snmpIfName = $snmpIfName . "." . $snmpkey ;
74! $snmpIfAlias = $snmpIfAlias . "." . $snmpkey ;
75!
76! push(@snmpoids,$snmpIfAdminStatus);
77! push(@snmpoids,$snmpIfOperStatus);
78! push(@snmpoids,$snmpIfDescr);
79! push(@snmpoids,$snmpIfName) if (defined $ifXTable) ;
80! push(@snmpoids,$snmpIfAlias) if (defined $ifXTable) ;
81
82! if (!defined($response = $session->get_request(@snmpoids))) {
83! $answer=$session->error;
84! $session->close;
85! $state = 'WARNING';
86! print ("$state: SNMP error: $answer\n");
87! exit $ERRORS{$state};
88 }
89
90- $answer = sprintf("host '%s', %s(%s) is %s\n",
91- $hostname,
92- $response->{$snmpIfDescr},
93- $snmpkey,
94- $ifOperStatus{$response->{$snmpIfOperStatus}}
95- );
96-
97-
98 ## Check to see if ifName match is requested and it matches - exit if no match
99 ## not the interface we want to monitor
100 if ( defined $name && not ($response->{$snmpIfName} eq $name) ) {
101--- 127,145 ----
102
103 ## Main function
104
105! # moved fetching of information to function to allow it to be recalled if
106! # bad snmpkey in cache file
107
108! fetch_data();
109! # If using ifDescr check to make sure database didn't return
110! # stale snmpkey
111! if (defined $ifdescr) {
112! if ($response->{$snmpIfDescr} ne $ifdescr) {
113! fetch_ifdescr();
114! fetch_data();
115! }
116 }
117
118 ## Check to see if ifName match is requested and it matches - exit if no match
119 ## not the interface we want to monitor
120 if ( defined $name && not ($response->{$snmpIfName} eq $name) ) {
121*************** exit $ERRORS{$state};
122*** 225,232 ****
123
124 ### subroutines
125
126 sub fetch_ifdescr {
127! if (!defined ($response = $session->get_table($snmpIfDescr))) {
128 $answer=$session->error;
129 $session->close;
130 $state = 'CRITICAL';
131--- 215,270 ----
132
133 ### subroutines
134
135+ sub fetch_data {
136+ my @snmpoids;
137+
138+ $snmpIfAdminStatus = $snmpIfAdminStatusOid . "." . $snmpkey;
139+ $snmpIfOperStatus = $snmpIfOperStatusOid . "." . $snmpkey;
140+ $snmpIfDescr = $snmpIfDescrOid . "." . $snmpkey;
141+ $snmpIfName = $snmpIfNameOid . "." . $snmpkey ;
142+ $snmpIfAlias = $snmpIfAliasOid . "." . $snmpkey ;
143+
144+ push(@snmpoids,$snmpIfAdminStatus);
145+ push(@snmpoids,$snmpIfOperStatus);
146+ push(@snmpoids,$snmpIfDescr);
147+ push(@snmpoids,$snmpIfName) if (defined $ifXTable) ;
148+ push(@snmpoids,$snmpIfAlias) if (defined $ifXTable) ;
149+
150+ if (!defined($response = $session->get_request(@snmpoids))) {
151+ $answer=$session->error;
152+ $session->close;
153+ $state = 'WARNING';
154+ print ("$state: SNMP error: $answer\n");
155+ exit $ERRORS{$state};
156+ }
157+
158+ $answer = sprintf("host '%s', %s(%s) is %s\n",
159+ $hostname,
160+ $response->{$snmpIfDescr},
161+ $snmpkey,
162+ $ifOperStatus{$response->{$snmpIfOperStatus}}
163+ );
164+ }
165+
166 sub fetch_ifdescr {
167! my %intcache;
168! dbmopen %intcache, $cacheFileName, 0600 or exit $ERRORS{'CRITICAL'};
169!
170! # check if we already checked cache file
171! if (!$cacheFileChecked) {
172! # check cache file for interface information, if exists use
173! # if not then update cache file for the entire host looking
174! # for this interface
175!
176! $cacheFileChecked = 1;
177! if (exists $intcache{$hostname.$ifdescr}) {
178! $snmpkey = $intcache{$hostname.$ifdescr};
179! dbmclose %intcache;
180! return $snmpkey;
181! }
182! }
183!
184! if (!defined ($response = $session->get_table($snmpIfDescrOid))) {
185 $answer=$session->error;
186 $session->close;
187 $state = 'CRITICAL';
188*************** sub fetch_ifdescr {
189*** 235,246 ****
190 exit $ERRORS{$state};
191 }
192
193 foreach $key ( keys %{$response}) {
194 if ($response->{$key} =~ /^$ifdescr$/) {
195! $key =~ /.*\.(\d+)$/;
196! $snmpkey = $1;
197 #print "$ifdescr = $key / $snmpkey \n"; #debug
198 }
199 }
200 unless (defined $snmpkey) {
201 $session->close;
202--- 273,297 ----
203 exit $ERRORS{$state};
204 }
205
206+ # snmpwalk succesful, empty cache file for this host
207+ # TODO: empty cache file for host
208+
209+ # escape "/" in ifdescr - very common in the Cisco world
210+ $ifdescr =~ s/\//\\\//g;
211+
212 foreach $key ( keys %{$response}) {
213+ $key =~ /.*\.(\d+)$/;
214+ my $cursnmpkey = $1;
215+
216 if ($response->{$key} =~ /^$ifdescr$/) {
217! #$key =~ /.*\.(\d+)$/;
218! #$snmpkey = $1;
219! $snmpkey = $cursnmpkey;
220 #print "$ifdescr = $key / $snmpkey \n"; #debug
221 }
222+
223+ # for each interface update cache file
224+ $intcache{$hostname.$response->{$key}} = $cursnmpkey;
225 }
226 unless (defined $snmpkey) {
227 $session->close;
228*************** sub fetch_ifdescr {
229*** 248,254 ****
230 printf "$state: Could not match $ifdescr on $hostname\n";
231 exit $ERRORS{$state};
232 }
233!
234 return $snmpkey;
235 }
236
237--- 299,306 ----
238 printf "$state: Could not match $ifdescr on $hostname\n";
239 exit $ERRORS{$state};
240 }
241!
242! dbmclose %intcache;
243 return $snmpkey;
244 }
245