PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/discovery/cisco-pw.inc.php

https://bitbucket.org/MelFlynn/observium
PHP | 79 lines | 62 code | 12 blank | 5 comment | 14 complexity | f667dfcabbd3dbe385d805d377e492e0 MD5 | raw file
Possible License(s): GPL-3.0, MIT
  1. <?php
  2. if ($config['enable_pseudowires'] && $device['os_group'] == "cisco")
  3. {
  4. unset($cpw_count);
  5. unset($cpw_exists);
  6. echo("Cisco Pseudowires : ");
  7. # FIXME snmp_walk
  8. $oids = shell_exec($config['snmpwalk'] . " -M " . $config['mibdir'] . " -m CISCO-IETF-PW-MIB -CI -Ln -Osqn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " cpwVcID");
  9. $oids = str_replace(".1.3.6.1.4.1.9.10.106.1.2.1.10.", "", $oids);
  10. $oids = trim($oids);
  11. foreach (explode("\n", $oids) as $oid)
  12. {
  13. if ($oid)
  14. {
  15. list($cpwOid, $cpwVcID) = explode(" ", $oid);
  16. if ($cpwOid)
  17. {
  18. list($cpw_remote_id) = explode(":", shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -m CISCO-IETF-PW-MPLS-MIB -Ln -Osqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " cpwVcMplsPeerLdpID." . $cpwOid));
  19. $interface_descr = trim(shell_exec($config['snmpwalk'] . " -M " . $config['mibdir'] . " -m CISCO-IETF-PW-MIB -Oqvn -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " cpwVcName." . $cpwOid));
  20. $cpw_remote_device = @mysql_result(mysql_query("SELECT device_id FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = '".$cpw_remote_id."' AND A.interface_id = I.interface_id"),0);
  21. $if_id = @mysql_result(mysql_query("SELECT `interface_id` FROM `ports` WHERE `ifDescr` = '$interface_descr' AND `device_id` = '".$device['device_id']."'"),0);
  22. if ($cpw_remote_device && $if_id)
  23. {
  24. $hostname = gethostbyid($cpw_remote_device);
  25. #echo("\nOid: " . $cpwOid . " cpwVcID: " . $cpwVcID . " Remote Id: " . $cpw_remote_id . "($hostname(".$cpw_remote_device.") -> $interface_descr($if_id))");
  26. if (mysql_result(mysql_query("SELECT count(*) FROM pseudowires WHERE `interface_id` = '$if_id'
  27. AND `cpwVcID`='".$cpwVcID."'"),0))
  28. {
  29. echo(".");
  30. }
  31. else
  32. {
  33. $insert_query = "INSERT INTO `pseudowires` (`interface_id`,`peer_device_id`,`peer_ldp_id`,`cpwVcID`,`cpwOid`) ";
  34. $insert_query .= "VALUES ('$if_id','$cpw_remote_device','$cpw_remote_id','$cpwVcID', '$cpwOid')";
  35. mysql_query($insert_query);
  36. echo("+");
  37. #echo($device['device_id'] . " $cpwOid $cpw_remote_device $if_id $cpwVcID\n");
  38. }
  39. $cpw_exists[] = $device['device_id'] . " $cpwOid $cpw_remote_device $if_id $cpwVcID";
  40. }
  41. }
  42. }
  43. }
  44. $sql = "SELECT * FROM pseudowires AS P, ports AS I, devices as D WHERE P.interface_id = I.interface_id AND I.device_id = D.device_id AND D.device_id = '".$device['device_id']."'";
  45. $query = mysql_query($sql);
  46. while ($cpw = mysql_fetch_assoc($query))
  47. {
  48. unset($exists);
  49. $i = 0;
  50. while ($i < count($cpw_exists) && !$exists)
  51. {
  52. $this_cpw = $cpw['device_id'] . " " . $cpw['cpwOid'] . " " . $cpw['peer_device_id'] . " " . $cpw['interface_id'] . " " . $cpw['cpwVcID'];
  53. if ($cpw_exists[$i] == $this_cpw) { $exists = 1;
  54. # echo($cpw_exists[$i]. " || $this_cpw \n");
  55. }
  56. $i++;
  57. }
  58. if (!$exists)
  59. {
  60. echo("-");
  61. # echo($this_cpw . "\n");
  62. mysql_query("DELETE FROM pseudowires WHERE pseudowire_id = '" . $cpw['pseudowire_id'] . "'");
  63. }
  64. }
  65. echo("\n");
  66. } # enable_pseudowires + os_group=cisco
  67. ?>