function contacttemplate_validate($app, $deployment, $contactTemplateInfo)
{
    foreach ($contactTemplateInfo as $key => $value) {
        switch ($key) {
            case "use":
            case "host_notification_period":
            case "service_notification_period":
            case "host_notification_commands":
            case "service_notification_commands":
                validateForbiddenChars($app, $deployment, '/[^\\w.-]/s', $key, $value);
                break;
            case "retain_status_information":
            case "retain_nonstatus_information":
            case "host_notifications_enabled":
            case "service_notifications_enabled":
            case "can_submit_commands":
                validateBinary($app, $deployment, $key, $value);
                break;
            case "host_notification_options":
                $opts = validateOptions($app, $deployment, $key, $value, array('d', 'u', 'r', 's', 'n'), true);
                $contactTemplateInfo[$key] = $opts;
                break;
            case "service_notification_options":
                $opts = validateOptions($app, $deployment, $key, $value, array('w', 'u', 'c', 'r', 's', 'n'), true);
                $contactTemplateInfo[$key] = $opts;
                break;
            default:
                break;
        }
    }
    // Don't register since we are a template
    $contactTemplateInfo['register'] = 0;
    return $contactTemplateInfo;
}
function serviceescalation_validate($app, $deployment, $serviceEscalationInfo)
{
    foreach ($serviceEscalationInfo as $key => $value) {
        switch ($key) {
            case "service_description":
            case "escalation_period":
                validateForbiddenChars($app, $deployment, '/[^\\w.-]/s', $key, $value);
                break;
            case "escalation_options":
                $opts = validateOptions($app, $deployment, $key, $value, array('w', 'u', 'c', 'r'), true);
                $serviceEscalationInfo[$key] = $opts;
                break;
            case "first_notification":
                validateInterval($app, $deployment, $key, $value, 0, 25);
                break;
            case "last_notification":
                validateInterval($app, $deployment, $key, $value, 0, 100);
                break;
            case "notification_interval":
                validateInterval($app, $deployment, $key, $value, 0, 1440);
                break;
            default:
                break;
        }
    }
    return $serviceEscalationInfo;
}
function servicegroup_validate($app, $deployment, $serviceGroupsInfo)
{
    foreach ($serviceGroupsInfo as $key => $value) {
        switch ($key) {
            case "notes":
                validateForbiddenChars($app, $deployment, '/[^\\w.-\\s]/s', $key, $value);
                break;
            case "notes_url":
            case "action_url":
                validateUrl($app, $deployment, $key, $value);
                break;
            default:
                break;
        }
    }
    return $serviceGroupsInfo;
}
function servicedependency_validate($app, $deployment, $serviceDependencyInfo)
{
    foreach ($serviceDependencyInfo as $key => $value) {
        switch ($key) {
            case "inherits_parent":
                validateBinary($app, $deployment, $key, $value);
                break;
            case "service_description":
            case "dependent_service_description":
            case "dependency_period":
                validateForbiddenChars($app, $deployment, '/[^\\w.-]/s', $key, $value);
                break;
            case "execution_failure_criteria":
            case "notification_failure_criteria":
                $opts = validateOptions($app, $deployment, $key, $value, array('o', 'w', 'u', 'c', 'p', 'n'), true);
                $serviceDependencyInfo[$key] = $opts;
                break;
            default:
                break;
        }
    }
    return $serviceDependencyInfo;
}
Exemple #5
0
function contact_validate($app, $deployment, $contactInfo)
{
    foreach ($contactInfo as $key => $value) {
        switch ($key) {
            case "use":
            case "host_notification_period":
            case "service_notification_period":
            case "host_notification_commands":
            case "service_notification_commands":
                validateForbiddenChars($app, $deployment, '/[^\\w.-]/s', $key, $value);
                break;
            case "retain_status_information":
            case "retain_nonstatus_information":
            case "host_notifications_enabled":
            case "service_notifications_enabled":
            case "can_submit_commands":
                validateBinary($app, $deployment, $key, $value);
                break;
            case "host_notification_options":
                $opts = validateOptions($app, $deployment, $key, $value, array('d', 'u', 'r', 's', 'n'), true);
                $contactInfo[$key] = $opts;
                break;
            case "service_notification_options":
                $opts = validateOptions($app, $deployment, $key, $value, array('w', 'u', 'c', 'r', 's', 'n'), true);
                $contactInfo[$key] = $opts;
                break;
            case "email":
                validateEmail($app, $deployment, $key, $value);
                break;
            case "pager":
                if (filter_var($value, FILTER_VALIDATE_EMAIL) === false) {
                    if (!preg_match("/^(?[2-9][0-8][0-9])?-[2-9][0-0]{2}-[0-9]{4}\$/", $value)) {
                        $apiResponse = new APIViewData(1, $deployment, "Unable use pager number provided, the value provided doesn't match the regex for pager or email address");
                        $apiResponse->setExtraResponseData('parameter', $key);
                        $apiResponse->setExtraResponseData('parameter-value', $value);
                        $apiResponse->setExtraResponseData('parameter-pager-regex', "/^(?[2-9][0-8][0-9])?-[2-9][0-0]{2}-[0-9]{4}\$/");
                        $app->halt(404, $apiResponse->returnJson());
                    }
                }
                break;
            case "contactgroups":
                if (is_array($value)) {
                    $value = implode(',', $value);
                }
                validateForbiddenChars($app, $deployment, '/[^\\w.-]/s', $key, $value);
                break;
            default:
                break;
        }
    }
    return $contactInfo;
}
function servicetemplate_validate($app, $deployment, $serviceTemplateInfo)
{
    foreach ($serviceTemplateInfo as $key => $value) {
        switch ($key) {
            case "use":
            case "check_period":
            case "event_handler":
            case "notification_period":
            case "icon_image":
                validateForbiddenChars($app, $deployment, '/[^\\w.-]/s', $key, $value);
                break;
            case "servicegroups":
                if (is_array($value)) {
                    $value = implode(',', $value);
                }
                validateForbiddenChars($app, $deployment, '/[^\\w.-]/s', $key, $value);
                break;
            case "is_volatile":
            case "active_checks_enabled":
            case "passive_checks_enabled":
            case "obsess_over_service":
            case "check_freshness":
            case "event_handler_enabled":
            case "flap_detection_enabled":
            case "parallelize_check":
            case "process_perf_data":
            case "retain_status_information":
            case "retain_nonstatus_information":
            case "notifications_enabled":
                validateBinary($app, $deployment, $key, $value);
                break;
            case "check_command":
                validateForbiddenChars($app, $deployment, '/[^\\w.-$\\/]/s', $key, $value);
                break;
            case "initial_state":
                $opts = validateOptions($app, $deployment, $key, $value, array('o', 'w', 'u', 'c'), true);
                $serviceTemplateInfo[$key] = $opts;
                break;
            case "max_check_attempts":
                validateInterval($app, $deployment, $key, $value, 1, 20);
                break;
            case "check_interval":
                validateInterval($app, $deployment, $key, $value, 1, 1440);
                break;
            case "retry_interval":
                validateInterval($app, $deployment, $key, $value, 1, 720);
                break;
            case "freshness_threshold":
                validateInterval($app, $deployment, $key, $value, 0, 86400);
                break;
            case "low_flap_threshold":
                validateInterval($app, $deployment, $key, $value, 0, 99);
                break;
            case "high_flap_threshold":
                validateInterval($app, $deployment, $key, $value, 0, 100);
                break;
            case "flap_detection_options":
                $opts = validateOptions($app, $deployment, $key, $value, array('o', 'w', 'c', 'u'), true);
                $serviceTemplateInfo[$key] = $opts;
                break;
            case "notification_interval":
            case "first_notification_delay":
                validateInterval($app, $deployment, $key, $value, 0, 1440);
                break;
            case "notification_options":
                $opts = validateOptions($app, $deployment, $key, $value, array('w', 'u', 'c', 'r', 'f', 's'), true);
                $serviceTemplateInfo[$key] = $opts;
                break;
            case "contacts":
            case "contact_groups":
                if (is_array($value)) {
                    $value = implode(',', $value);
                }
                validateForbiddenChars($app, $deployment, '/[^\\w.-]/s', $key, $value);
                break;
            case "stalking_options":
                $opts = validateOptions($app, $deployment, $key, $value, array('o', 'w', 'u', 'c'), true);
                $serviceTemplateInfo[$key] = $opts;
                break;
            case "icon_image_alt":
                validateForbiddenChars($app, $deployment, '/[^\\w.-\\s]/s', $key, $value);
                break;
            default:
                break;
        }
    }
    // We never want to see single threaded checks running, force this...
    if (!isset($serviceTemplateInfo['parallelize_check']) || empty($serviceTemplateInfo['parallelize_check'])) {
        $serviceTemplateInfo['parallelize_check'] = 1;
    }
    // Don't register since we are a template
    $serviceTemplateInfo['register'] = 0;
    return $serviceTemplateInfo;
}
Exemple #7
0
         case "low_service_flap_threshold":
             validateInterval($app, $deployment, $key, $nagiosConfigInfo[$key], 0, 99);
             break;
         case "host_inter_check_delay_method":
         case "service_inter_check_delay_method":
             validateForbiddenChars($app, $deployment, '/[^\\dnds]/s', $key, $nagiosConfigInfo[$key]);
             break;
         case "max_host_check_spread":
         case "max_service_check_spread":
             validateInterval($app, $deployment, $key, $nagiosConfigInfo[$key], 1, 1440);
             break;
         case "max_debug_file_size":
             validateInterval($app, $deployment, $key, $nagiosConfigInfo[$key], 1, 104857600);
             break;
         case "service_interleave_factor":
             validateForbiddenChars($app, $deployment, '/[^\\ds]/s', $key, $nagiosConfigInfo[$key]);
             break;
         case "sleep_time":
             validateInterval($app, $deployment, $key, $nagiosConfigInfo[$key], 0, 5);
             break;
         case "host_perfdata_file_mode":
         case "service_perfdata_file_mode":
             validateOptions($app, $deployment, $key, $nagiosConfigInfo[$key], array('w', 'a', 'p'));
             break;
         default:
             break;
     }
 }
 check_revision_status($deployment);
 $deployRev = RevDeploy::getDeploymentNextRev($deployment);
 if (RevDeploy::existsDeploymentNagiosCfg($deployment, $deployRev) === true) {
function hosttemplate_validate($app, $deployment, $hostTemplateInfo)
{
    foreach ($hostTemplateInfo as $key => $value) {
        switch ($key) {
            case "check_command":
                validateForbiddenChars($app, $deployment, '/[^\\w.-$\\/]/s', $key, $value);
                break;
            case "initial_state":
                $opts = validateOptions($app, $deployment, $key, $value, array('o', 'd', 'u'), true);
                $hostTemplateInfo[$key] = $opts;
                break;
            case "max_check_attempts":
                validateInterval($app, $deployment, $key, $value, 1, 20);
                break;
            case "check_interval":
            case "notification_interval":
            case "first_notification_delay":
                validateInterval($app, $deployment, $key, $value, 1, 1440);
                break;
            case "retry_interval":
                validateInterval($app, $deployment, $key, $value, 1, 720);
                break;
            case "active_checks_enabled":
            case "passive_checks_enabled":
            case "obsess_over_host":
            case "check_freshness":
            case "event_handler_enabled":
            case "flap_detection_enabled":
            case "process_perf_data":
            case "retain_status_information":
            case "retain_nonstatus_information":
            case "notifications_enabled":
                validateBinary($app, $deployment, $key, $value);
                break;
            case "check_period":
            case "event_handler":
            case "notification_period":
            case "icon_image":
            case "vrml_image":
            case "statusmap_image":
            case "use":
                validateForbiddenChars($app, $deployment, '/[^\\w.-]/s', $key, $value);
                break;
            case "freshness_threshold":
                validateInterval($app, $deployment, $key, $value, 0, 86400);
                break;
            case "low_flap_threshold":
                validateInterval($app, $deployment, $key, $value, 0, 99);
                break;
            case "high_flap_threshold":
                validateInterval($app, $deployment, $key, $value, 0, 100);
                break;
            case "flap_detection_options":
                $opts = validateOptions($app, $deployment, $key, $value, array('o', 'd', 'u'), true);
                $hostTemplateInfo[$key] = $opts;
                break;
            case "notification_options":
                $opts = validateOptions($app, $deployment, $key, $value, array('d', 'u', 'r', 'f', 's'), true);
                $hostTemplateInfo[$key] = $opts;
                break;
            case "stalking_options":
                $opts = validateOptions($app, $deployment, $key, $value, array('o', 'd', 'u'), true);
                $hostTemplateInfo[$key] = $opts;
                break;
            case "notes_url":
            case "action_url":
                validateUrl($app, $deployment, $key, $value);
                break;
            case "icon_image_alt":
            case "notes":
                validateForbiddenChars($app, $deployment, '/[^\\w.-\\s]/s', $key, $value);
                break;
            case "hostgroups":
            case "parents":
                if (is_array($value)) {
                    $value = implode(',', $value);
                }
                validateForbiddenChars($app, $deployment, '/[^\\w.-]/s', $key, $value);
                break;
            default:
                break;
        }
    }
    // Don't register since we are a template
    $hostTemplateInfo['register'] = 0;
    return $hostTemplateInfo;
}