Advertisement
Guest User

mantis

a guest
Jan 16th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.08 KB | None | 0 0
  1. #!/usr/bin/php
  2. <?php
  3. // CLI Only
  4.  
  5. $date = date("Y-m-d H:i:s");
  6. if(PHP_SAPI != 'cli') {
  7.         exit("{$date} : ERROR: This program must be run from the command line\n");
  8. }
  9.  
  10. // Check of parameters
  11. //for($i = 1; $i <= 7; $i++) {
  12. for($i = 1; $i <= 8; $i++) {
  13.         if(!isset($argv[$i])) {
  14. //              exit("{$date} : ERROR: Example of using: {$argv['0']} <IP> <STATE> <NAME> <LASTSTATE> <STATETYPE>
  15.                 exit("{$date} : ERROR: Example of using: {$argv['0']} <IP> <STATE> <NAME> <LASTSTATE> <STATETYPE>
  16.        }
  17. }
  18.  
  19. // Parameters
  20. $dev = $argv['1'];
  21. $state = $argv['2'];
  22. $node = $argv['3'];
  23. $laststate = $argv['4'];
  24. $statetype = $argv['5'];
  25. $attempt = $argv['6'];
  26. $downtime = $argv['7'];
  27. $reg = $argv['8'];
  28.  
  29. $excarr= array(
  30.                 '10.0.1.1',
  31.                '10.0.2.1',
  32.                '10.0.3.1',
  33.                '10.0.4.1',
  34.                '10.0.5.1',
  35. <------><------>'10.0.6.1',
  36. <------><------>'10.0.11.1',
  37. <------><------>'10.0.12.1',
  38. <------><------>'10.0.14.1',
  39. <------><------>'10.0.15.1',
  40. <------><------>'10.0.17.1',
  41. <------><------>'10.0.18.1',
  42. <------><------>'10.0.20.1',
  43. <------><------>'10.0.22.1',
  44. <------><------>'10.0.24.1',
  45. <------><------>'10.0.26.1',
  46. <------><------>'10.0.27.1',
  47. <------><------>'10.0.30.1',
  48. <------><------>'10.0.34.1',
  49. <------><------>'10.0.40.1',
  50. <------><------>'10.0.44.1',
  51. <------><------>'10.0.51.1',
  52. <------><------>'10.0.52.1',
  53. <------><------>'10.0.56.1',
  54. <------><------>'10.0.57.1',
  55. <------><------>'10.0.61.1',
  56. <------><------>'10.0.69.1',
  57. <------><------>'10.0.73.1',
  58. <------><------>'10.0.78.1',
  59. <------><------>'10.0.80.1',
  60. <------><------>'10.0.81.1',
  61. <------><------>'10.0.90.1',
  62. <------><------>'10.0.91.1',
  63.                '10.0.95.1',
  64.                '10.0.97.1'
  65.                );
  66.  
  67. $dbuser = 'problemDetection';
  68. $dbpass = 'ySFfEpjZvmTdhZRy';
  69. $dbhost = '10.0.0.220';
  70. $dbname = 'dhcpdb';
  71.  
  72. $soapUrl = "http://mssql02.sibset-office.211.ru/SwitchMonitroing/SwitchMonitroingTerrasoftCRM.asmx?WSDL";
  73. //if(($statetype == 'HARD' and $attempt == 3 and $state != 'UP') || ($statetype == 'HARD' and $attempt == 1 and $s
  74. //if(($statetype == 'HARD' and $attempt == 3 and $state != 'UP' and $downtime == 0) || ($statetype == 'HARD' and $
  75. if(($statetype == 'HARD' and $state != 'UP' and $downtime == 0) || ($statetype == 'HARD' and $attempt == 1 and $st
  76. //if(($statetype == 'HARD' and $state != 'UP' and $downtime == 0 and !preg_match('/^10.0.90./',$dev) and !preg_mat
  77.         if($reg == 1) {
  78. <------><------>#if (preg_match('/^10\.0\.(\d+)\.1$/',$dev,$match) and !in_array($dev,$excarr)){
  79. <------><------>#<----->$z = sprintf('%02d', $match[1]);
  80. <------><------>#        $dev = "10.0.0.1$z";
  81. <------><------>#}
  82.                if($db = mysql_connect($dbhost, $dbuser, $dbpass)) {
  83.                         if(!mysql_select_db($dbname, $db)) {
  84.                                 exit("{$date} : {$dev} : ERROR: could not select or find dhcpdb database\n");
  85.                         }
  86.                         mysql_set_charset('utf8', $db);
  87.                 } else {
  88.                         exit("{$date} : {$dev} : ERROR: DHCPDB Database connection failed\n");
  89.                 }
  90.                 $dbResult = mysql_query("select terrasoftID from devices where ipaddr=inet_aton('{$dev}')", $db);
  91.                 if(mysql_num_rows($dbResult) == 1) {
  92.                         list($terrasoftID) = mysql_fetch_row($dbResult);
  93.                                 if (empty($terrasoftID)) $terrasoftID = '';
  94.                                 $client = new SoapClient($soapUrl, array('trace' => 1));
  95.                                 try {
  96.                                         $result = $client->ProblemDetection(array('ID' => $terrasoftID, 'IP' => $d
  97.                                 } catch(SoapFault $fault) {
  98.                                         echo "{$date} : {$dev} : ERROR: " . $fault->getMessage();
  99.                                 }
  100.                 } else {
  101.                          exit("{$date} : {$dev} : ERROR: Couldn't find any device with such IP!\n");
  102.                 }
  103.                 mysql_close($db);
  104.         }
  105. }
  106. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement