コード例 #1
0
 public function deploy()
 {
     foreach ($this->destinations as $destination) {
         // set new swap_id
         $swap_id = NConf_HTML::set_swap_id('swap_deploy');
         // reset informations
         NConf_HTML::set_info('', 'reset');
         // add informations if status is FALSE
         // if there are host informations, add them
         if (!empty($destination["host"])) {
             NConf_HTML::set_info(NConf_HTML::table_row_check('Host:', '', $destination["host"]), 'add');
         }
         // call the command and get its status back
         // also catch direct output (of errors etc.) which are not intercepted in the submodule
         ob_start();
         $status = $this->command($destination);
         if (ob_get_contents()) {
             NConf_DEBUG::set(ob_get_contents(), 'ERROR', $this->name);
             NConf_HTML::set_info(NConf_HTML::table_row_check('Error/Info:', 'ERROR', 'Please have a look at the NConf error message at the bottom of the page'), 'add');
         }
         ob_end_clean();
         // Table output
         echo NConf_HTML::table_row_check(NConf_HTML::swap_opener($swap_id, $destination["title"], TRUE), $status);
         $content = NConf_HTML::table_begin('class="table_content ui-widget-content"', array(102, 50, ''));
         $content .= NConf_HTML::get_info();
         $content .= NConf_HTML::table_end();
         // create row with detailed feedback
         echo NConf_HTML::table_row_text($content, '', 'colspan=3', TRUE);
         // add status to history log
         NConf_Deployment::history($destination["title"], $status);
     }
 }
コード例 #2
0
 public function run_deployment()
 {
     if (!ALLOW_DEPLOYMENT) {
         echo NConf_HTML::limit_space(NConf_HTML::show_error('ERROR', 'Deployment functionality is currently disabled.'));
     } elseif (ALLOW_DEPLOYMENT && (!ALLOW_DIRECT_DEPLOYMENT && empty($_POST["status"]))) {
         echo NConf_HTML::limit_space(NConf_HTML::show_error('ERROR', 'Please first run the "Generate Nagios config".'));
     } elseif (ALLOW_DEPLOYMENT && ALLOW_DIRECT_DEPLOYMENT || ALLOW_DEPLOYMENT && (!ALLOW_DIRECT_DEPLOYMENT && (!empty($_POST["status"]) && $_POST["status"] == "OK"))) {
         echo NConf_HTML::table_begin('class="table_checks"', array(170, 50, ''));
         // DEPLOY
         // First do the local module
         $local_module = $this->modules["local"];
         if ($local_module->configured()) {
             NConf_DEBUG::set('', 'DEBUG', 'Deploying ' . $local_module->name);
             echo NConf_HTML::table_row_text(NConf_HTML::title($local_module->name, '', 'class="content_header"'));
             NConf_DEBUG::set($local_module->destinations, 'DEBUG', $local_module->name);
             $local_module->deploy();
             echo NConf_HTML::table_row_text(NConf_HTML::line(), '', 'colspan=3');
         }
         // Then do all other modules if they are configured
         foreach ($this->modules as $module) {
             // Dont do the "local" module
             // Check also if module is configured
             if ($module->name == "local" or !$module->configured()) {
                 continue;
             }
             NConf_DEBUG::set('', 'DEBUG', 'Deploying ' . $module->name);
             echo NConf_HTML::table_row_text(NConf_HTML::title($module->name, '', 'class="content_header"'));
             NConf_DEBUG::set($module->destinations, 'DEBUG', $module->name);
             // run the deploy
             $module->deploy();
             echo NConf_HTML::table_row_text(NConf_HTML::line(), '', 'colspan=3');
         }
         echo NConf_HTML::table_end();
     } else {
         echo NConf_HTML::text('Deployment is enabled, but your configuration seems to have errors.', TRUE, 'div', 'class="attention"');
     }
 }
コード例 #3
0
ファイル: functions.php プロジェクト: pasichnichenko/nconf
function inheritance_HostToService($host_id, $mode = '')
{
    //NConf_DEBUG::open_group('inheritance for host_id: "'.$host_id.'"', 1);
    # Handling inheritance to services
    # check for host data
    if ($mode == 'apply_inheritance') {
        if (empty($_POST["apply_inheritance"][$host_id])) {
            // continue if service is empty
            NConf_DEBUG::set("not applying for host: " . $host_id, 'DEBUG', 'Inheritance filter');
            return;
        }
    }
    # These services will be modified
    $services = db_templates("get_services_from_host_id", $host_id);
    # array of inherited attributes
    $change_attrs = array("check_period" => "check period", "notification_period" => "notification period", "contact_groups" => "contact groups");
    $class_id = db_templates("get_id_of_class", "service");
    # array for preview functionality
    $preview_array = array();
    # make a diff with each service to detect which items must be linked and which must be removed
    foreach ($services as $service_id => $service_name) {
        NConf_DEBUG::open_group('inheritance for service: "' . $service_name . '"', 1);
        # initial value for history entry "edited"
        $edited = FALSE;
        $preview_array[$service_name] = array();
        if ($mode == 'apply_inheritance') {
            if (empty($_POST["apply_inheritance"][$host_id][$service_id])) {
                // continue if service is empty
                NConf_DEBUG::set("not applying for service: " . $service_name, 'DEBUG', 'Inheritance filter');
                continue;
            }
        }
        foreach ($change_attrs as $change_attr => $change_attr_friendly_name) {
            NConf_DEBUG::open_group("attribute: " . $change_attr_friendly_name, 2);
            if ($mode == 'apply_inheritance' and empty($_POST["apply_inheritance"][$host_id][$service_id][$change_attr])) {
                // continue if service is empty
                NConf_DEBUG::set("not applying for attribute: " . $change_attr_friendly_name, 'DEBUG', 'Inheritance filter');
                continue;
            }
            NConf_DEBUG::open_group("lookup values", 3);
            $attr_id = db_templates("get_attr_id", "service", $change_attr);
            # get current host data
            $new_items = db_templates("get_linked_item", $host_id, $change_attr, '', 'array_2fieldsTOassoc');
            # get current service data
            $current_items = db_templates("get_linked_item", $service_id, $change_attr, '', 'array_2fieldsTOassoc');
            # diff to get items to add
            $diff_array = array_diff($new_items, $current_items);
            # diff to get items to remove
            $diff_array2 = array_diff($current_items, $new_items);
            /* debugging:
               echo "<pre>";
               var_dump($diff_array);
               var_dump($diff_array2);
               echo "</pre>";
               */
            if ($mode == "preview") {
                $preview_array[$service_id]["service_name"] = $service_name;
                $preview_array[$service_id]["attrs"][$attr_id] = array("attr_name" => $change_attr, "attr_friendly_name" => $change_attr_friendly_name, "current" => $current_items, "new" => $new_items, "differs" => !empty($diff_array) or !empty($diff_array2));
                //                $preview_array[$service_id]["attrs"][$attr_id]["differs"] = (!empty($diff_array) OR !empty($diff_array2) );
            } else {
                # make changes in the DB
                // until now, there are no such special attributes:
                //$lac_OR_bidirectional = check_link_as_child_or_bidirectional($change_attr, $class_id);
                // perhaps later there must also be this logic.
                # remove items
                if (!empty($diff_array2)) {
                    NConf_DEBUG::open_group("remove items");
                    foreach ($diff_array2 as $attr_removed_name => $attr_removed_id) {
                        $query = 'DELETE FROM ItemLinks
                                    WHERE fk_id_item=' . $service_id . '
                                        AND fk_id_attr = "' . $attr_id . '"
                                        AND fk_item_linked2 = "' . $attr_removed_id . '"
                                 ';
                        db_handler($query, "delete", 'delete linked item "' . $attr_removed_name . '"');
                        history_add("unassigned", $change_attr_friendly_name, $attr_removed_name, $service_id);
                        $edited = TRUE;
                    }
                }
                # add items
                if (!empty($diff_array)) {
                    NConf_DEBUG::open_group("add items");
                    foreach ($diff_array as $attr_add_name => $attr_add_id) {
                        $query = 'INSERT INTO ItemLinks (fk_id_item,fk_item_linked2,fk_id_attr)
                                    VALUES (' . $service_id . ',' . $attr_add_id . ', ' . $attr_id . ')';
                        db_handler($query, "insert", 'insert linked item "' . $attr_add_name . '"');
                        history_add("assigned", $change_attr_friendly_name, $attr_add_name, $service_id);
                        $edited = TRUE;
                    }
                }
            }
        }
        NConf_DEBUG::close_group(2);
        //NConf_DEBUG::open_group('history "edited" entry', 1);
        # history entry "edited"
        if ($mode == "preview") {
            # clean service if nothing will change
            if (empty($preview_array[$service_name])) {
                unset($preview_array[$service_name]);
            }
        } elseif ($edited) {
            history_add("edited", "service", $service_name, $service_id);
        }
    }
    if ($mode == "preview") {
        # print preview
        # create a table with checkboxes for applying inheritance
        $preview = NConf_HTML::table_begin('class="ui-nconf-table ui-widget ui-widget-content ui-nconf-max-width"', array('', 50, 120, 100, 100));
        $preview .= '<thead class="ui-widget-header">
                      <tr>
                        <th>service</th>
                        <th name="checkbox_toggle_all" class="center pointer">update</th>
                        <th>attribute</th>
                        <th>service value</th>
                        <th>host value</th>
                      </tr>
                     </thead>';
        $bg_class = "even";
        foreach ($preview_array as $service_id => $service) {
            $i = 0;
            $service_name = $service["service_name"];
            # handle background for each service
            if ($bg_class == "odd") {
                $bg_class = "even";
            } else {
                $bg_class = "odd";
            }
            foreach ($service["attrs"] as $attribute_id => $values) {
                $i++;
                $preview .= '<tr class="' . $bg_class . '">';
                if ($i == 1) {
                    $preview .= '<td rowspan="' . count($service["attrs"]) . '" class="align_top">' . NConf_HTML::title($service_name) . '</td>';
                }
                # check box for applying
                $preview .= '<td class="center">';
                if ($values["differs"]) {
                    $preview .= '<input type="checkbox" class="pointer" name="apply_inheritance[' . $host_id . '][' . $service_id . '][' . $values["attr_name"] . ']" value="' . $attribute_id . '" checked=checked>';
                }
                $preview .= '</td>';
                $preview .= '<td>' . $values["attr_friendly_name"] . '</td>';
                # current values
                $preview .= '<td name="checkbox_toggle"';
                // color red
                if ($values["differs"]) {
                    $preview .= ' class="red"';
                }
                $preview .= '>';
                # generate value list
                $current_values = array_flip($values["current"]);
                $preview .= implode(", ", $current_values);
                $preview .= "</td>";
                # new values
                $preview .= '<td name="checkbox_toggle"';
                // color green
                if ($values["differs"]) {
                    $preview .= ' class="bold"';
                }
                $preview .= '>';
                # generate value list
                $new_values = array_flip($values["new"]);
                $preview .= implode(", ", $new_values);
                $preview .= "</td>";
                $preview .= "</tr>";
            }
        }
        $preview .= NConf_HTML::table_end();
        return $preview;
    } elseif (!NConf_DEBUG::status('ERROR') and $mode != "preview") {
        NConf_DEBUG::set('', 'INFO', 'Successfully updated all linked services.');
    }
    return;
}