2
2
/* This file is part of JFFNMS
3
3
* Copyright (C) <2002-2005> Javier Szyszlican <javier@szysz.com>
4
* Copyright (C) 2012 Craig Small <csmall@enc.com.au>
4
5
* This program is licensed under the GNU GPL, full terms in the LICENSE file
7
8
function poller_verify_interface_number ($options)
9
static $static_buffer = array();
11
$current_ifindex = $options['interfacenumber'];
13
//Search by Interface Name (ie. Switches or not IP interfaces)
14
if (($options['address']=='') && ($options['interfacenumber']!='')) // if IP is empty and it has a interfacenumber in the DB
16
if (!array_key_exists('ifIndex', $static_buffer) && $options['ro_community'])
17
{ //Get the Tables via SNMP only once
19
$ifIndex_oid = '.1.3.6.1.2.1.2.2.1.1';
20
$static_buffer['ifIndex'] = snmp_walk($options['host_ip'],$options['ro_community'],$ifIndex_oid);
21
include_once(jffnms_shared('catos')); //Load CatOS code
22
if (is_catos($options['host_ip'], $options['ro_community'])) //If this host is CatOS
23
$ifDescr_oid = CATOS_IFDESCR_OID;
25
$ifDescr_oid = '.1.3.6.1.2.1.2.2.1.2'; //Use the Standard IF-MIB OID
26
$static_buffer['ifDescr'] = snmp_walk($options['host_ip'],$options['ro_community'],$ifDescr_oid);
28
if (is_array($static_buffer['ifDescr']))
30
$pos = array_search($options['interface'],$static_buffer['ifDescr']); //Find the DB interface name and return the index
31
if (is_numeric($pos)) //if we found something
32
$current_ifindex = $static_buffer['ifIndex'][$pos]; //return the ifIndex at the same position we found this
34
} else //Search by IP Address
35
if (strpos($options['address'],'.') === FALSE) // if the address is not an IP, use that as the IfIndex
37
$current_ifindex = $options['address'];
38
} else //If its an IP Address
39
if (!empty($options['ro_community'])) //and has SNMP
40
$current_ifindex = snmp_get($options['host_ip'],$options['ro_community'], //Get the interface index
41
'.1.3.6.1.2.1.4.20.1.2.'.$options['address']); //by looking up the IP
42
return $current_ifindex;
10
static $static_buffer = array();
11
static $buffer_age = 0;
12
$buffer_max_len=20; // 20 hosts of details
13
$buffer_max_age=180; // 3 minutes of buffer
14
require_once(jffnms_shared('catos'));
15
require_once(jffnms_shared('webos'));
16
$ifIndex_oid = '.1.3.6.1.2.1.2.2.1.1';
18
$current_ifindex = $options['interfacenumber'];
20
if (empty($options['ro_community']))
22
$rocommunity = $options['ro_community'];
23
$ip = $options['host_ip'];
24
$hid = $options['host_id'];
26
# If the interface has no IP address then we need to search by name
27
if (($options['address']=='')) {
28
// Check freshness of buffer
29
if ($buffer_age + $buffer_max_age < time()) {
30
$static_buffer = array();
33
if (!array_key_exists($hid, $static_buffer)) {
34
if (sizeof($static_buffer) > $buffer_max_len)
35
array_shift($static_buffer);
36
$ifIndex = snmp_walk($options['host_ip'],$options['ro_community'],$ifIndex_oid);
37
include_once(jffnms_shared('catos'));
38
if (is_catos($options['host_ip'], $options['ro_community']))
39
$ifDescr_oid = CATOS_IFDESCR_OID;
41
$ifDescr_oid = '.1.3.6.1.2.1.2.2.1.2';
42
$ifDescr = snmp_walk($options['host_ip'],$options['ro_community'],$ifDescr_oid);
43
if (is_array($ifIndex) && count($ifIndex) > 0 && is_array($ifDescr) && count($ifDescr) > 0) {
44
$static_buffer[$hid] = array('ifIndex'=>$ifIndex, 'ifDescr'=>$ifDescr);
46
return -1; //snmpwalk failed
50
if ($current_ifindex != '') {
51
$pos = array_search($current_ifindex, $static_buffer[$hid]['ifIndex']);
52
if (is_numeric($pos) && array_key_exists($pos, $static_buffer[$hid]['ifDescr'])) {
53
$polled_ifdescr = $static_buffer[$hid]['ifDescr'][$pos];
54
if (strncmp($polled_ifdescr, $options['interface'],30)==0)
55
return $current_ifindex; // we found it
58
// If not matched, then its changed, find new index
59
$pos = array_search($options['interface'],$static_buffer[$hid]['ifDescr']); //Find the DB interface name and return the index
60
if (is_numeric($pos) and array_key_exists($pos, $static_buffer[$hid]['ifIndex'])) //if we found something
61
return $static_buffer[$hid]['ifIndex'][$pos]; //return the ifIndex at the same position we found this
62
} else //Search by IP Address
63
if (strpos($options['address'],'.') === FALSE) // if the address is not an IP, use that as the IfIndex
65
return $options['address'];
66
} else //If its an IP Address
67
return snmp_get($options['host_ip'],$options['ro_community'], //Get the interface index
68
'.1.3.6.1.2.1.4.20.1.2.'.$options['address']); //by looking up the IP