} } $required_keys = array('service_description', 'first_notification', 'last_notification', 'notification_interval'); if (empty($serviceEscalationInfo)) { $apiResponse = new APIViewData(1, $deployment, "Unable to detect any service escalation information to process"); $app->halt(404, $apiResponse->returnJson()); } // A bit of param validation if (!isset($serviceEscalationInfo['name']) || empty($serviceEscalationInfo['name'])) { $apiResponse = new APIViewData(1, $deployment, "Unable to detect name parameter"); $app->halt(404, $apiResponse->returnJson()); } elseif (preg_match_all('/[^\\w.-]/s', $serviceEscalationInfo['name'], $forbidden)) { $apiResponse = new APIViewData(1, $deployment, "Unable to use service escalation name specified, detected forbidden characters " . implode('', array_unique($forbidden[0]))); $app->halt(404, $apiResponse->returnJson()); } validateContacts($app, $deployment, $serviceEscalationInfo); // Lets make sure we have the minimum required keys for defining a service escalation foreach ($required_keys as $rkey) { if (!isset($serviceEscalationInfo[$rkey]) || empty($serviceEscalationInfo[$rkey])) { $apiResponse = new APIViewData(1, $deployment, "Unable to detect required parameter {$rkey} " . serviceescalation_rkeyMessage($rkey)); $app->halt(404, $apiResponse->returnJson()); } } $serviceEscalationInfo = serviceescalation_validate($app, $deployment, $serviceEscalationInfo); $deployRev = RevDeploy::getDeploymentNextRev($deployment); if (RevDeploy::existsDeploymentSvcEscalation($deployment, $serviceEscalationInfo['name'], $deployRev) === true) { RevDeploy::modifyDeploymentSvcEscalation($deployment, $serviceEscalationInfo['name'], $serviceEscalationInfo, $deployRev); $apiResponse = new APIViewData(0, $deployment, "Successfully Modified Service Escalation " . $serviceEscalationInfo['name']); } else { RevDeploy::createDeploymentSvcEscalation($deployment, $serviceEscalationInfo['name'], $serviceEscalationInfo, $deployRev); $apiResponse = new APIViewData(0, $deployment, "Successfully Created Service Escalation " . $serviceEscalationInfo['name']);
$app->halt(404, $apiResponse->returnJson()); } elseif (preg_match_all('/[^\\w.-]/s', $serviceTemplateInfo['name'], $forbidden)) { $apiResponse = new APIViewData(1, $deployment, "Unable to use service template name specified, detected forbidden characters " . implode('', array_unique($forbidden[0]))); $app->halt(404, $apiResponse->returnJson()); } if (!isset($serviceTemplateInfo['alias']) || empty($serviceTemplateInfo['alias'])) { $apiResponse = new APIViewData(1, $deployment, "Unable to detect alias parameter (longer human readable information about service, one simple line)"); $app->halt(404, $apiResponse->returnJson()); } elseif (preg_match_all('/[^\\w.-\\s]/s', $serviceTemplateInfo['alias'], $forbidden)) { $apiResponse = new APIViewData(1, $deployment, "Unable to use service template alias specified, detected forbidden characters " . implode('', array_unique($forbidden[0]))); $app->halt(404, $apiResponse->returnJson()); } // You get a pass if you have the use template key defined... if (!isset($serviceTemplateInfo['use']) || empty($serviceTemplateInfo['use'])) { // Lets make sure we have the minimum required keys for defining a service template validateContacts($app, $deployment, $serviceTemplateInfo); foreach ($required_keys as $rkey) { if (!isset($serviceTemplateInfo[$rkey]) || empty($serviceTemplateInfo[$rkey])) { $apiResponse = new APIViewData(1, $deployment, "Unable to detect required parameter {$rkey} " . servicetemplate_rkeyMessage($rkey)); $app->halt(404, $apiResponse->returnJson()); } } } $serviceTemplateInfo = servicetemplate_validate($app, $deployment, $serviceTemplateInfo); $deployRev = RevDeploy::getDeploymentNextRev($deployment); if (RevDeploy::existsDeploymentSvcTemplate($deployment, $serviceTemplateInfo['name'], $deployRev) === true) { RevDeploy::modifyDeploymentSvcTemplate($deployment, $serviceTemplateInfo['name'], $serviceTemplateInfo, $deployRev); $apiResponse = new APIViewData(0, $deployment, "Successfully Modified Service Template " . $serviceTemplateInfo['name']); } else { RevDeploy::createDeploymentSvcTemplate($deployment, $serviceTemplateInfo['name'], $serviceTemplateInfo, $deployRev); $apiResponse = new APIViewData(0, $deployment, "Successfully Created Service Template " . $serviceTemplateInfo['name']);
$app->halt(404, $apiResponse->returnJson()); } elseif (preg_match_all('/[^\\w.-]/s', $hostTemplateInfo['name'], $forbidden)) { $apiResponse = new APIViewData(1, $deployment, "Unable to use host template name specified, detected forbidden characters " . implode('', array_unique($forbidden[0]))); $app->halt(404, $apiResponse->returnJson()); } if (!isset($hostTemplateInfo['alias']) || empty($hostTemplateInfo['alias'])) { $apiResponse = new APIViewData(1, $deployment, "Unable to detect alias parameter (longer human readable information about host, one simple line)"); $app->halt(404, $apiResponse->returnJson()); } elseif (preg_match_all('/[^\\w.-\\s]/s', $hostTemplateInfo['alias'], $forbidden)) { $apiResponse = new APIViewData(1, $deployment, "Unable to use host template alias specified, detected forbidden characters " . implode('', array_unique($forbidden[0]))); $app->halt(404, $apiResponse->returnJson()); } // You get a pass if you have the use template key defined... if (!isset($hostTemplateInfo['use']) || empty($hostTemplateInfo['use'])) { // Lets make sure we have the minimum required keys for defining a host template validateContacts($app, $deployment, $hostTemplateInfo); foreach ($required_keys as $rkey) { if (!isset($hostTemplateInfo[$rkey]) || empty($hostTemplateInfo[$rkey])) { $apiResponse = new APIViewData(1, $deployment, "Unable to detect required parameter {$rkey} " . hosttemplate_rkeyMessage($rkey)); $app->halt(404, $apiResponse->returnJson()); } } } $hostTemplateInfo = hosttemplate_validate($app, $deployment, $hostTemplateInfo); $deployRev = RevDeploy::getDeploymentNextRev($deployment); if (RevDeploy::existsDeploymentHostTemplate($deployment, $hostTemplateInfo['name'], $deployRev) === true) { RevDeploy::modifyDeploymentHostTemplate($deployment, $hostTemplateInfo['name'], $hostTemplateInfo, $deployRev); $apiResponse = new APIViewData(0, $deployment, "Successfully Modified Host Template " . $hostTemplateInfo['name']); } else { RevDeploy::createDeploymentHostTemplate($deployment, $hostTemplateInfo['name'], $hostTemplateInfo, $deployRev); $apiResponse = new APIViewData(0, $deployment, "Successfully Created Host Template " . $hostTemplateInfo['name']);