GetDBHost(), $sBackupFile); $sBackupFile = str_replace('__DB__', $oConfig->GetDBName(), $sBackupFile); $sBackupFile = str_replace('__SUBNAME__', $oConfig->GetDBSubName(), $sBackupFile); if (is_null($iRefTime)) { $sBackupFile = strftime($sBackupFile); } else { $sBackupFile = strftime($sBackupFile, $iRefTime); } return $sBackupFile; } function RaiseAlarm($sMessage) { echo "$sMessage\n"; try { $sTicketLogin = ReadMandatoryParam('check_ticket_login'); $sTicketPwd = ReadMandatoryParam('check_ticket_pwd'); $sTicketTitle = ReadMandatoryParam('check_ticket_title'); $sTicketCustomer = ReadMandatoryParam('check_ticket_customer'); $sTicketService = ReadMandatoryParam('check_ticket_service'); $sTicketSubcategory = ReadMandatoryParam('check_ticket_service_subcategory'); $sTicketWorkgroup = ReadMandatoryParam('check_ticket_workgroup'); $sTicketImpactedServer = ReadMandatoryParam('check_ticket_impacted_server'); } catch (Exception $e) { echo "The ticket could not be created: ".$e->GetMessage()."\n"; return; } $sMessage = "Server: [[Server:".$sTicketImpactedServer."]]\n".$sMessage; require_once(APPROOT.'webservices/itopsoaptypes.class.inc.php'); //$sItopRootDefault = 'http'.((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS']!='off')) ? 's' : '').'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].dirname($_SERVER['SCRIPT_NAME']).'/../..'; //$sItopRoot = utils::ReadParam('check_ticket_itop', $sItopRootDefault); $sItopRoot = ReadMandatoryParam('check_ticket_itop'); $sWsdlUri = $sItopRoot.'/webservices/itop.wsdl.php'; //$sWsdlUri .= '?service_category='; $aSOAPMapping = SOAPMapping::GetMapping(); ini_set("soap.wsdl_cache_enabled","0"); $oSoapClient = new SoapClient( $sWsdlUri, array( 'trace' => 1, 'classmap' => $aSOAPMapping, // defined in itopsoaptypes.class.inc.php ) ); try { $oRes = $oSoapClient->CreateIncidentTicket ( $sTicketLogin, /* login */ $sTicketPwd, /* password */ $sTicketTitle, /* title */ $sMessage, /* description */ null, /* caller */ new SOAPExternalKeySearch(array(new SOAPSearchCondition('name', $sTicketCustomer))), /* customer */ new SOAPExternalKeySearch(array(new SOAPSearchCondition('name', $sTicketService))), /* service */ new SOAPExternalKeySearch(array(new SOAPSearchCondition('name', $sTicketSubcategory))), /* service subcategory */ '', /* product */ new SOAPExternalKeySearch(array(new SOAPSearchCondition('name', $sTicketWorkgroup))), /* workgroup */ array( new SOAPLinkCreationSpec( 'Server', array(new SOAPSearchCondition('name', $sTicketImpactedServer)), array() ), ), /* impacted cis */ '1', /* impact */ '1' /* urgency */ ); } catch(Exception $e) { echo "The ticket could not be created: SOAP Exception = '".$e->getMessage()."'\n"; } //echo "
\n"; //print_r($oRes); //echo "\n"; if ($oRes->status) { $sTicketName = $oRes->result[0]->values[1]->value; echo "Created ticket: $sTicketName\n"; } else { echo "ERROR: Failed to create the ticket in target iTop ($sItopRoot)\n"; foreach ($oRes->errors->messages as $oMessage) { echo $oMessage->text."\n"; } } } ////////// // Main try { utils::UseParamFile(); } catch(Exception $e) { echo "Error: ".$e->GetMessage()."\n"; exit; } $sZipArchiveFile = MakeArchiveFileName(); echo date('Y-m-d H:i:s')." - Checking file: $sZipArchiveFile\n"; if (file_exists($sZipArchiveFile)) { if ($aStat = stat($sZipArchiveFile)) { $iSize = (int) $aStat['size']; $iMIN = utils::ReadParam('check_size_min', 0); if ($iSize > $iMIN) { echo "Found the archive\n"; $sOldArchiveFile = MakeArchiveFileName(time() - 86400); // yesterday's archive if (file_exists($sOldArchiveFile)) { if ($aOldStat = stat($sOldArchiveFile)) { echo "Comparing its size with older file: $sOldArchiveFile\n"; $iOldSize = (int) $aOldStat['size']; $fVariationPercent = 100 * ($iSize - $iOldSize) / $iOldSize; $sVariation = round($fVariationPercent, 2)." percent(s)"; $iREDUCTIONMAX = utils::ReadParam('check_size_reduction_max'); if ($fVariationPercent < -$iREDUCTIONMAX) { RaiseAlarm("Backup file '$sZipArchiveFile' changed by $sVariation, expecting a reduction limited to $iREDUCTIONMAX percents of the original size"); } elseif ($fVariationPercent < 0) { echo "Size variation: $sVariation (the maximum allowed reduction is $iREDUCTIONMAX) \n"; } else { echo "The archive grew by: $sVariation\n"; } } } } else { RaiseAlarm("Backup file '$sZipArchiveFile' too small (Found: $iSize, while expecting $iMIN bytes)"); } } else { RaiseAlarm("Failed to stat backup file '$sZipArchiveFile'"); } } else { RaiseAlarm("Missing backup file '$sZipArchiveFile'"); } ?>