Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/php
- <?php
- // CLI Only
- $date = date("Y-m-d H:i:s");
- if(PHP_SAPI != 'cli') {
- exit("{$date} : ERROR: This program must be run from the command line\n");
- }
- // Check of parameters
- //for($i = 1; $i <= 7; $i++) {
- for($i = 1; $i <= 8; $i++) {
- if(!isset($argv[$i])) {
- // exit("{$date} : ERROR: Example of using: {$argv['0']} <IP> <STATE> <NAME> <LASTSTATE> <STATETYPE>
- exit("{$date} : ERROR: Example of using: {$argv['0']} <IP> <STATE> <NAME> <LASTSTATE> <STATETYPE>
- }
- }
- // Parameters
- $dev = $argv['1'];
- $state = $argv['2'];
- $node = $argv['3'];
- $laststate = $argv['4'];
- $statetype = $argv['5'];
- $attempt = $argv['6'];
- $downtime = $argv['7'];
- $reg = $argv['8'];
- $excarr= array(
- '10.0.1.1',
- '10.0.2.1',
- '10.0.3.1',
- '10.0.4.1',
- '10.0.5.1',
- <------><------>'10.0.6.1',
- <------><------>'10.0.11.1',
- <------><------>'10.0.12.1',
- <------><------>'10.0.14.1',
- <------><------>'10.0.15.1',
- <------><------>'10.0.17.1',
- <------><------>'10.0.18.1',
- <------><------>'10.0.20.1',
- <------><------>'10.0.22.1',
- <------><------>'10.0.24.1',
- <------><------>'10.0.26.1',
- <------><------>'10.0.27.1',
- <------><------>'10.0.30.1',
- <------><------>'10.0.34.1',
- <------><------>'10.0.40.1',
- <------><------>'10.0.44.1',
- <------><------>'10.0.51.1',
- <------><------>'10.0.52.1',
- <------><------>'10.0.56.1',
- <------><------>'10.0.57.1',
- <------><------>'10.0.61.1',
- <------><------>'10.0.69.1',
- <------><------>'10.0.73.1',
- <------><------>'10.0.78.1',
- <------><------>'10.0.80.1',
- <------><------>'10.0.81.1',
- <------><------>'10.0.90.1',
- <------><------>'10.0.91.1',
- '10.0.95.1',
- '10.0.97.1'
- );
- $dbuser = 'problemDetection';
- $dbpass = 'ySFfEpjZvmTdhZRy';
- $dbhost = '10.0.0.220';
- $dbname = 'dhcpdb';
- $soapUrl = "http://mssql02.sibset-office.211.ru/SwitchMonitroing/SwitchMonitroingTerrasoftCRM.asmx?WSDL";
- //if(($statetype == 'HARD' and $attempt == 3 and $state != 'UP') || ($statetype == 'HARD' and $attempt == 1 and $s
- //if(($statetype == 'HARD' and $attempt == 3 and $state != 'UP' and $downtime == 0) || ($statetype == 'HARD' and $
- if(($statetype == 'HARD' and $state != 'UP' and $downtime == 0) || ($statetype == 'HARD' and $attempt == 1 and $st
- //if(($statetype == 'HARD' and $state != 'UP' and $downtime == 0 and !preg_match('/^10.0.90./',$dev) and !preg_mat
- if($reg == 1) {
- <------><------>#if (preg_match('/^10\.0\.(\d+)\.1$/',$dev,$match) and !in_array($dev,$excarr)){
- <------><------>#<----->$z = sprintf('%02d', $match[1]);
- <------><------># $dev = "10.0.0.1$z";
- <------><------>#}
- if($db = mysql_connect($dbhost, $dbuser, $dbpass)) {
- if(!mysql_select_db($dbname, $db)) {
- exit("{$date} : {$dev} : ERROR: could not select or find dhcpdb database\n");
- }
- mysql_set_charset('utf8', $db);
- } else {
- exit("{$date} : {$dev} : ERROR: DHCPDB Database connection failed\n");
- }
- $dbResult = mysql_query("select terrasoftID from devices where ipaddr=inet_aton('{$dev}')", $db);
- if(mysql_num_rows($dbResult) == 1) {
- list($terrasoftID) = mysql_fetch_row($dbResult);
- if (empty($terrasoftID)) $terrasoftID = '';
- $client = new SoapClient($soapUrl, array('trace' => 1));
- try {
- $result = $client->ProblemDetection(array('ID' => $terrasoftID, 'IP' => $d
- } catch(SoapFault $fault) {
- echo "{$date} : {$dev} : ERROR: " . $fault->getMessage();
- }
- } else {
- exit("{$date} : {$dev} : ERROR: Couldn't find any device with such IP!\n");
- }
- mysql_close($db);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement