swpoll.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * SNMP switch polling
  4. */
  5. if (ubRouting::get('action') == 'swpoll') {
  6. $switchPollingProcess = new StarDust('SWPOLL_ALL');
  7. $allDevices = sp_SnmpGetAllDevices();
  8. $allTemplates = sp_SnmpGetAllModelTemplates();
  9. $allTemplatesAssoc = sp_SnmpGetModelTemplatesAssoc();
  10. $allusermacs = zb_UserGetAllMACs();
  11. $alladdress = zb_AddressGetFullCityaddresslist();
  12. $alldeadswitches = zb_SwitchesGetAllDead();
  13. $swpollLogData = '';
  14. $swpollLogPath = 'exports/swpolldata.log';
  15. $altCfg = $ubillingConfig->getAlter();
  16. $hordeTimeout = 0;
  17. if (@$altCfg['HORDE_OF_SWITCHES'] > 1) {
  18. $hordeTimeout = ubRouting::filters($altCfg['HORDE_OF_SWITCHES'], 'int');
  19. }
  20. if (!empty($allDevices)) {
  21. if ($switchPollingProcess->notRunning()) {
  22. //start new polling
  23. $switchPollingProcess->start();
  24. file_put_contents($swpollLogPath, date("Y-m-d H:i:s") . ' [SWPOLLSTART]' . "\n", FILE_APPEND);
  25. foreach ($allDevices as $io => $eachDevice) {
  26. if (!@$altCfg['HORDE_OF_SWITCHES']) {
  27. $swpollLogData = '';
  28. if (!empty($allTemplatesAssoc)) {
  29. if (isset($allTemplatesAssoc[$eachDevice['modelid']])) {
  30. //dont poll dead devices
  31. if (!isset($alldeadswitches[$eachDevice['ip']])) {
  32. $deviceTemplate = $allTemplatesAssoc[$eachDevice['modelid']];
  33. sp_SnmpPollDevice($eachDevice['ip'], $eachDevice['snmp'], $allTemplates, $deviceTemplate, $allusermacs, $alladdress, $eachDevice['snmpwrite'], true);
  34. $swpollLogData = date("Y-m-d H:i:s") . ' ' . $eachDevice['ip'] . ' [OK]' . PHP_EOL;
  35. print($swpollLogData);
  36. } else {
  37. $swpollLogData = date("Y-m-d H:i:s") . ' ' . $eachDevice['ip'] . ' [FAIL] SWITCH DEAD' . PHP_EOL;
  38. print($swpollLogData);
  39. }
  40. } else {
  41. $swpollLogData = date("Y-m-d H:i:s") . ' ' . $eachDevice['ip'] . ' [FAIL] NO TEMPLATE' . PHP_EOL;
  42. print($swpollLogData);
  43. }
  44. }
  45. //put some log data about polling
  46. @file_put_contents($swpollLogPath, $swpollLogData, FILE_APPEND);
  47. } else {
  48. //For the horde!
  49. $switchPollingProcess->runBackgroundProcess('/bin/ubapi "horde&devid=' . $eachDevice['id'] . '"', $hordeTimeout);
  50. }
  51. }
  52. $switchPollingProcess->stop();
  53. die('OK:SWPOLL');
  54. } else {
  55. die('SKIP:SWPOLL_ALREADY_RUNNING');
  56. }
  57. } else {
  58. die('ERROR:SWPOLL_NODEVICES');
  59. }
  60. }