~ubuntu-branches/debian/stretch/jffnms/stretch

« back to all changes in this revision

Viewing changes to engine/pollers/verify_interface_number.php

  • Committer: Package Import Robot
  • Author(s): Craig Small
  • Date: 2012-05-27 17:25:29 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20120527172529-w0bkk0qo3jz8vkhx
Tags: 0.9.3-1
* New upstream release
* Adjusted configurations for new apache standard Closes: #669853
* Removed orphan files Closes: #672385
* Generate valid DB config
* Fixup default config files Closes: #655654

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
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
5
6
 */
6
7
 
7
8
function poller_verify_interface_number ($options)
8
9
{
9
 
  static $static_buffer = array();
10
 
 
11
 
  $current_ifindex = $options['interfacenumber'];
12
 
 
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
15
 
  {
16
 
    if (!array_key_exists('ifIndex', $static_buffer) && $options['ro_community'])
17
 
    { //Get the Tables via SNMP only once
18
 
  
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;
24
 
      else
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);
27
 
    }
28
 
    if (is_array($static_buffer['ifDescr']))
29
 
    {
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
33
 
    }
34
 
  } else //Search by IP Address
35
 
    if (strpos($options['address'],'.') === FALSE)   // if the address is not an IP, use that as the IfIndex
36
 
    {
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';
 
17
 
 
18
    $current_ifindex = $options['interfacenumber'];
 
19
 
 
20
    if (empty($options['ro_community']))
 
21
        return -1;
 
22
    $rocommunity = $options['ro_community'];
 
23
    $ip = $options['host_ip'];
 
24
    $hid = $options['host_id'];
 
25
 
 
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();
 
31
            $buffer_age = time();
 
32
        }
 
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;
 
40
            else
 
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);
 
45
           } else {
 
46
               return -1; //snmpwalk failed
 
47
           }
 
48
 
 
49
        }
 
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
 
56
            }
 
57
        }
 
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
 
64
        {
 
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
 
69
    return -1;
43
70
}
 
71
 
 
72
 
44
73
?>