Get('db_host'), $sBackupFile); $sBackupFile = str_replace('__DB__', $oConfig->Get('db_name'), $sBackupFile); $sBackupFile = str_replace('__SUBNAME__', $oConfig->Get('db_subname'), $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'); $oConfig = GetConfig(); $sItopRootConfig = $oConfig->GetModuleSetting('itop-backup', 'itop_backup_incident'); if (empty($sItopRootConfig)) { // by default getting self ! // we could have '' as config value... $sItopRootConfig = $oConfig->Get('app_root_url'); } try { $sWsdlUri = $sItopRootConfig.'/webservices/itop.wsdl.php'; $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 ) ); } catch (Exception $e) { echo "ERROR: Failed to read WSDL of the target iTop ($sItopRootConfig)\n"; return; } 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"; return; } //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 ($sItopRootConfig)\n"; foreach ($oRes->errors->messages as $oMessage) { echo $oMessage->text."\n"; } } } ////////// // Main try { utils::UseParamFile(); } catch(Exception $e) { echo "Error: ".$e->GetMessage()."\n"; exit; } if (utils::IsModeCLI()) { echo date('Y-m-d H:i:s')." - running check-backup utility\n"; try { $sAuthUser = ReadMandatoryParam('auth_user'); $sAuthPwd = ReadMandatoryParam('auth_pwd'); } catch (Exception $e) { $sMessage = $e->getMessage(); ToolsLog::Error($sMessage); echo $sMessage; exit; } $bDownloadBackup = false; if (UserRights::CheckCredentials($sAuthUser, $sAuthPwd)) { UserRights::Login($sAuthUser); // Login & set the user's language } else { ExitError($oP, "Access restricted or wrong credentials ('$sAuthUser')"); } } else { require_once(APPROOT.'application/loginwebpage.class.inc.php'); LoginWebPage::DoLogin(); // Check user rights and prompt if needed $bDownloadBackup = utils::ReadParam('download', false); } if (!UserRights::IsAdministrator()) { ExitError($oP, "Access restricted to administors"); } // N°1802 : was moved from script param to config file (avoid direct call with untrusted param value) $sItopRootParam = utils::ReadParam('check_ticket_itop', null, true, 'raw_data'); if (!empty($sItopRootParam)) { echo "ERROR: parameter 'check_ticket_itop' should now be specified in the config file 'itop_backup_incident' parameter\n"; return; } $sZipArchiveFile = MakeArchiveFileName().'.tar.gz'; $sZipArchiveFileForDisplay = utils::HtmlEntities($sZipArchiveFile); echo date('Y-m-d H:i:s')." - Checking file: $sZipArchiveFileForDisplay\n"; if (!file_exists($sZipArchiveFile)) { RaiseAlarm("Missing backup file '$sZipArchiveFileForDisplay'"); return; } $aStat = stat($sZipArchiveFile); if (!$aStat) { RaiseAlarm("Failed to stat backup file '$sZipArchiveFileForDisplay'"); return; } $iSize = (int)$aStat['size']; $iMIN = utils::ReadParam('check_size_min', 0); if ($iSize <= $iMIN) { RaiseAlarm("Backup file '$sZipArchiveFileForDisplay' too small (Found: $iSize, while expecting $iMIN bytes)"); return; } echo "Found the archive\n"; $sOldArchiveFile = MakeArchiveFileName(time() - 86400).'.tar.gz'; // yesterday's archive $sOldArchiveFileForDisplay = utils::HtmlEntities($sOldArchiveFile); if (file_exists($sOldArchiveFile)) { if ($aOldStat = stat($sOldArchiveFile)) { echo "Comparing its size with older file: $sOldArchiveFileForDisplay\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 '$sZipArchiveFileForDisplay' 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"; } } }