function form_save() { global $export_types; if (isset($_POST["save_component_export"])) { $xml_data = get_item_xml($_POST["export_type"], $_POST["export_item_id"], (isset($_POST["include_deps"]) ? $_POST["include_deps"] : "") == "" ? false : true); if ($_POST["output_format"] == "1") { include_once "./include/top_header.php"; print "<table width='98%' align='center'><tr><td><pre>" . htmlspecialchars($xml_data) . "</pre></td></tr></table>"; include_once "./include/bottom_footer.php"; } elseif ($_POST["output_format"] == "2") { header("Content-type: application/xml"); print $xml_data; } elseif ($_POST["output_format"] == "3") { header("Content-type: application/xml"); header("Content-Disposition: attachment; filename=cacti_" . $_POST["export_type"] . "_" . strtolower(clean_up_name(db_fetch_cell(str_replace("|id|", $_POST["export_item_id"], $export_types[$_POST["export_type"]]["title_sql"])))) . ".xml"); print $xml_data; } } }
function generate_data_source_path($local_data_id) { $host_part = ""; $ds_part = ""; /* try any prepend the name with the host description */ $host_name = db_fetch_cell("select host.description from (host,data_local) where data_local.host_id=host.id and data_local.id=$local_data_id"); if (!empty($host_name)) { $host_part = strtolower(clean_up_name($host_name)) . "_"; } /* then try and use the internal DS name to identify it */ $data_source_rrd_name = db_fetch_cell("select data_source_name from data_template_rrd where local_data_id=$local_data_id order by id"); if (!empty($data_source_rrd_name)) { $ds_part = strtolower(clean_up_name($data_source_rrd_name)); }else{ $ds_part = "ds"; } /* put it all together using the local_data_id at the end */ $new_path = "<path_rra>/$host_part$ds_part" . "_" . "$local_data_id.rrd"; /* update our changes to the db */ db_execute("update data_template_data set data_source_path='$new_path' where local_data_id=$local_data_id"); return $new_path; }
} if ($alertm != '' && $alert['method'] == 1) { $resend = true; if ($alert['repeat_alert'] > 0) { $found = syslog_db_fetch_cell('SELECT count(*) FROM syslog_logs WHERE alert_id=' . $alert['id'] . "\n\t\t\t\t\tAND logtime>'{$date}'"); if ($found) { $resend = false; } } if ($resend) { syslog_sendemail(trim($alert['email']), '', 'Event Alert - ' . $alert['name'], $html ? $htmlm : $alertm, $smsalert); if ($alert['open_ticket'] == 'on' && strlen(read_config_option('syslog_ticket_command'))) { if (is_executable(read_config_option('syslog_ticket_command'))) { exec(read_config_option('syslog_ticket_command') . " --alert-name='" . clean_up_name($alert['name']) . "'" . " --severity='" . $alert['severity'] . "'" . " --hostlist='" . implode(',', $hostlist) . "'" . " --message='" . $alert['message'] . "'"); } } } } } } api_plugin_hook('plugin_syslog_after_processing'); /* move syslog records to the syslog table */ syslog_db_execute('INSERT INTO `' . $syslogdb_default . '`.`syslog` (logtime, priority_id, facility_id, program_id, host_id, message) SELECT TIMESTAMP(`' . $syslog_incoming_config['dateField'] . '`, `' . $syslog_incoming_config['timeField'] . '`), priority_id, facility_id, program_id, host_id, message FROM (SELECT date, time, priority_id, facility_id, program_id, host_id, message FROM syslog_incoming AS si INNER JOIN syslog_hosts AS sh ON sh.host=si.host
function get_data_source_item_name($data_template_rrd_id) { if (empty($data_template_rrd_id)) { return ""; } $data_source = db_fetch_row("select\n\t\tdata_template_rrd.data_source_name,\n\t\tdata_template_data.name\n\t\tfrom (data_template_rrd,data_template_data)\n\t\twhere data_template_rrd.local_data_id=data_template_data.local_data_id\n\t\tand data_template_rrd.id={$data_template_rrd_id}"); /* use the cacti ds name by default or the user defined one, if entered */ if (empty($data_source["data_source_name"])) { /* limit input to 19 characters */ $data_source_name = clean_up_name($data_source["name"]); $data_source_name = substr(strtolower($data_source_name), 0, 19 - strlen($data_template_rrd_id)) . $data_template_rrd_id; return $data_source_name; } else { return $data_source["data_source_name"]; } }
function get_data_source_item_name($data_template_rrd_id) { if (empty($data_template_rrd_id)) { return ''; } $data_source = db_fetch_row_prepared('SELECT data_template_rrd.data_source_name, data_template_data.name FROM (data_template_rrd, data_template_data) WHERE data_template_rrd.local_data_id = data_template_data.local_data_id AND data_template_rrd.id = ?', array($data_template_rrd_id)); /* use the cacti ds name by default or the user defined one, if entered */ if (empty($data_source['data_source_name'])) { /* limit input to 19 characters */ $data_source_name = clean_up_name($data_source['name']); $data_source_name = substr(strtolower($data_source_name), 0, 19 - strlen($data_template_rrd_id)) . $data_template_rrd_id; return $data_source_name; } else { return $data_source['data_source_name']; } }
function settings() { global $colors, $tabs_graphs, $settings_graphs, $current_user, $current_user; /* you cannot have per-user graph settings if cacti's user management is not turned on */ if (read_config_option("auth_method") == 0) { raise_message(6); display_output_messages(); return; } /* Find out whether this user has right here */ if($current_user["graph_settings"] == "") { print "<strong><font size='+1' color='#FF0000'>" . __("YOU DO NOT HAVE RIGHTS TO CHANGE GRAPH SETTINGS") . "</font></strong>"; include_once(CACTI_BASE_PATH . "/include/bottom_footer.php"); exit; } if (read_config_option("auth_method") != 0) { if ($current_user["policy_graphs"] == "1") { $sql_where = "where user_auth_tree.user_id is null"; }elseif ($current_user["policy_graphs"] == "2") { $sql_where = "where user_auth_tree.user_id is not null"; } $settings_graphs["tree"]["default_tree_id"]["sql"] = get_graph_tree_array(true); } /* draw the categories tabs on the top of the page */ print "<form method='post' action='graph_settings.php'>\n"; # the tabs print "<table width='100%' cellspacing='0' cellpadding='0' align='center'><tr><td><div class='tabs'>\n"; if (sizeof($settings_graphs) > 0) { foreach (array_keys($settings_graphs) as $tab_short_name) { print "<div><a id='tab_" . clean_up_name($tabs_graphs[$tab_short_name]) . "' " . (($tab_short_name == "General") ? "class='tab tabSelected'" : "class='tab tabDefault'") . " onClick='selectTab(\"" . clean_up_name($tabs_graphs[$tab_short_name]) . "\")' href='#'>$tabs_graphs[$tab_short_name]</a></div>\n"; } } print "</div></td></tr></table>\n"; # the tab contents while (list($tab_short_name, $tab_fields) = each($settings_graphs)) { print "<table cellpadding='0' cellspacing='0' width='100%'><tr><td><div class='tab_settings' id='settings_" . clean_up_name($tabs_graphs[$tab_short_name]) . "'>\n"; html_start_box("<strong>" . __("Graph Settings") . " (" . $tabs_graphs[$tab_short_name] . ")</strong>", "100", $colors["header"], 0, "center", "", false, "Tab_Settings_" . clean_up_name($tabs_graphs[$tab_short_name])); $header_items = array(__("Field"), __("Value")); print "<tr><td>"; html_header($header_items, 2, true, "Header_Settings_" . clean_up_name($tabs_graphs[$tab_short_name]),'left wp100'); $form_array = array(); while (list($field_name, $field_array) = each($tab_fields)) { $form_array += array($field_name => $tab_fields[$field_name]); if ((isset($field_array["items"])) && (is_array($field_array["items"]))) { while (list($sub_field_name, $sub_field_array) = each($field_array["items"])) { if (graph_config_value_exists($sub_field_name, $_SESSION["sess_user_id"])) { $form_array[$field_name]["items"][$sub_field_name]["form_id"] = 1; } $form_array[$field_name]["items"][$sub_field_name]["value"] = db_fetch_cell("select value from settings_graphs where name='$sub_field_name' and user_id=" . $_SESSION["sess_user_id"]); } }else{ if (graph_config_value_exists($field_name, $_SESSION["sess_user_id"])) { $form_array[$field_name]["form_id"] = 1; } $form_array[$field_name]["value"] = db_fetch_cell("select value from settings_graphs where name='$field_name' and user_id=" . $_SESSION["sess_user_id"]); } } draw_edit_form( array( "config" => array("no_form_tag" => true), "fields" => $form_array ) ); print "</table></td></tr>"; /* end of html_header */ html_end_box(); print "</div></td></tr></table>\n"; } if (isset($_SERVER["HTTP_REFERER"])) { $timespan_sel_pos = strpos($_SERVER["HTTP_REFERER"],"&predefined_timespan"); if ($timespan_sel_pos) { $_SERVER["HTTP_REFERER"] = substr($_SERVER["HTTP_REFERER"],0,$timespan_sel_pos); } } form_hidden_box("referer", "graph_view.php",""); form_hidden_box("save_component_graph_config","1",""); form_save_button_alt("", "save", "save"); ?> <script type="text/javascript"> <!-- function selectTab(tab) { $('.tab_settings').hide(); $('.tab').removeClass("tabSelected"); $('.tab').addClass("tabDefault"); $('#settings_'+tab).show(); $('#tab_'+tab).removeClass("tabDefault"); $('#tab_'+tab).addClass("tabSelected"); } $().ready(function() { selectTab('General'); }); //--> </script> <?php include(CACTI_BASE_PATH . "/include/bottom_footer.php"); }
function api_data_source_path_get_update($data_source_id) { require_once(CACTI_BASE_PATH . "/lib/sys/string.php"); $host_part = ""; $ds_part = ""; /* we don't want to change the current path if one already exists */ if ((empty($data_source_id)) || (db_fetch_cell("select rrd_path from data_source where id = $data_source_id") != "")) { return; } /* try any prepend the name with the host description */ $hostname = db_fetch_cell("select host.description from host,data_source where data_source.host_id=host.id and data_source.id = $data_source_id"); if ($hostname != "") { $host_part = strtolower(clean_up_name($hostname)) . "_"; } /* then try and use the internal DS name to identify it */ $data_source_item_name = db_fetch_cell("select data_source_name from data_source_item where data_source_id = $data_source_id order by id limit 1"); if ($data_source_item_name != "") { $ds_part = strtolower(clean_up_name($data_source_item_name)); }else{ $ds_part = "ds"; } $rrd_path = "<path_rra>/$host_part$ds_part" . "_" . "$data_source_id.rrd"; /* update our changes to the db */ db_execute("update data_source set rrd_path = '$rrd_path' where id = $data_source_id"); return $rrd_path; }
function thold_check_threshold(&$thold_data) { global $config, $plugins, $debug, $thold_types; $name = db_fetch_cell_prepared('SELECT data_source_name FROM data_template_rrd WHERE id = ?', array($thold_data['data_template_rrd_id'])); thold_debug('Checking Threshold:' . ' Name: ' . $name . ', local_data_id: ' . $thold_data['local_data_id'] . ', data_template_rrd_id: ' . $thold_data['data_template_rrd_id'] . ', value: ' . $thold_data['lastread']); $debug = false; // Do not proceed if we have chosen to globally disable all alerts if (read_config_option('thold_disable_all') == 'on') { thold_debug('Threshold checking is disabled globally'); return; } $alert_exempt = read_config_option('alert_exempt'); /* check for exemptions */ $weekday = date('l'); if (($weekday == 'Saturday' || $weekday == 'Sunday') && $alert_exempt == 'on') { thold_debug('Threshold checking is disabled by global weekend exemption'); return; } /* check for the weekend exemption on the threshold level */ if (($weekday == 'Saturday' || $weekday == 'Sunday') && $thold_data['exempt'] == 'on') { thold_debug('Threshold checking is disabled by global weekend exemption'); return; } /* don't alert for this host if it's selected for maintenance */ if (api_plugin_is_enabled('maint') || in_array('maint', $plugins)) { include_once $config['base_path'] . '/plugins/maint/functions.php'; if (plugin_maint_check_cacti_host($thold_data['host_id'])) { thold_debug('Threshold checking is disabled by maintenance schedule'); return; } } $local_graph_id = $thold_data['local_graph_id']; /* only alert if Device is in UP mode (not down, unknown, or recovering) */ $h = db_fetch_row('SELECT * FROM host WHERE id=' . $thold_data['host_id']); if (sizeof($h) && $h['status'] != 3) { thold_debug('Threshold checking halted by Device Status (' . $h['status'] . ')'); return; } /* pull the cached name, if not present, it means that the graph hasn't polled yet */ $t = db_fetch_assoc('SELECT id, name, name_cache FROM data_template_data WHERE local_data_id = ' . $thold_data['local_data_id'] . ' ORDER BY id LIMIT 1'); /* pull a few default settings */ $global_alert_address = read_config_option('alert_email'); $global_notify_enabled = read_config_option('alert_notify_default') == 'on'; $logset = read_config_option('alert_syslog') == 'on'; $deadnotify = read_config_option('alert_deadnotify') == 'on'; $realert = read_config_option('alert_repeat'); $alert_trigger = read_config_option('alert_trigger'); $alert_bl_trigger = read_config_option('alert_bl_trigger'); $httpurl = read_config_option('base_url'); $thold_send_text_only = read_config_option('thold_send_text_only'); $thold_snmp_traps = read_config_option('thold_alert_snmp') == 'on'; $thold_snmp_warning_traps = read_config_option('thold_alert_snmp_warning') != 'on'; $thold_snmp_normal_traps = read_config_option('thold_alert_snmp_normal') != 'on'; $cacti_polling_interval = read_config_option('poller_interval'); /* remove this after adding an option for it */ $thold_show_datasource = thold_datasource_required($thold_data['name'], $name); $trigger = $thold_data['thold_fail_trigger'] == '' ? $alert_trigger : $thold_data['thold_fail_trigger']; $warning_trigger = $thold_data['thold_warning_fail_trigger'] == '' ? $alert_trigger : $thold_data['thold_warning_fail_trigger']; $alertstat = $thold_data['thold_alert']; $alert_emails = get_thold_alert_emails($thold_data); $warning_emails = get_thold_warning_emails($thold_data); $alert_msg = get_thold_alert_text($name, $thold_data, $h, $thold_data['lastread'], $thold_data['local_graph_id']); $warn_msg = get_thold_warning_text($name, $thold_data, $h, $thold_data['lastread'], $thold_data['local_graph_id']); $thold_snmp_data = get_thold_snmp_data($name, $thold_data, $h, $thold_data['lastread']); $file_array = ''; if ($thold_send_text_only != 'on') { if (!empty($thold_data['local_graph_id'])) { $file_array[] = array('local_graph_id' => $thold_data['local_graph_id'], 'local_data_id' => $thold_data['local_data_id'], 'rra_id' => 0, 'file' => "{$httpurl}/graph_image.php?local_graph_id=" . $thold_data['local_graph_id'] . '&rra_id=0&view_type=tree', 'mimetype' => 'image/png', 'filename' => clean_up_name($thold_data['name'])); } } $url = $httpurl . '/graph.php?local_graph_id=' . $thold_data['local_graph_id'] . '&rra_id=all'; switch ($thold_data['thold_type']) { case 0: /* hi/low */ if ($thold_data['lastread'] != '') { $breach_up = $thold_data['thold_hi'] != '' && $thold_data['lastread'] > $thold_data['thold_hi']; $breach_down = $thold_data['thold_low'] != '' && $thold_data['lastread'] < $thold_data['thold_low']; $warning_breach_up = $thold_data['thold_warning_hi'] != '' && $thold_data['lastread'] > $thold_data['thold_warning_hi']; $warning_breach_down = $thold_data['thold_warning_low'] != '' && $thold_data['lastread'] < $thold_data['thold_warning_low']; } else { $breach_up = $breach_down = $warning_breach_up = $warning_breach_down = false; } /* is in alert status */ if ($breach_up || $breach_down) { $notify = false; thold_debug('Threshold HI / Low check breached HI:' . $thold_data['thold_hi'] . ' LOW:' . $thold_data['thold_low'] . ' VALUE:' . $thold_data['lastread']); $thold_data['thold_fail_count']++; $thold_data['thold_alert'] = $breach_up ? STAT_HI : STAT_LO; /* Re-Alert? */ $ra = $thold_data['thold_fail_count'] > $trigger && $thold_data['repeat_alert'] != 0 && $thold_data['thold_fail_count'] % $thold_data['repeat_alert'] == 0; if ($thold_data['thold_fail_count'] == $trigger || $ra) { $notify = true; } $subject = 'ALERT: ' . $thold_data['name'] . ($thold_show_datasource ? " [{$name}]" : '') . ' ' . ($ra ? 'is still' : 'went') . ' ' . ($breach_up ? 'above' : 'below') . ' threshold of ' . ($breach_up ? $thold_data['thold_hi'] : $thold_data['thold_low']) . ' with ' . $thold_data['lastread']; if ($notify) { thold_debug('Alerting is necessary'); if ($logset == 1) { logger($thold_data['name'], $ra ? 'realert' : 'alert', $breach_up ? $thold_data['thold_hi'] : $thold_data['thold_low'], $thold_data['lastread'], $trigger, $thold_data['thold_fail_count'], $url); } if (trim($alert_emails) != '') { thold_mail($alert_emails, '', $subject, $alert_msg, $file_array); } if ($thold_snmp_traps) { $thold_snmp_data['eventClass'] = 3; $thold_snmp_data['eventSeverity'] = $thold_data['snmp_event_severity']; $thold_snmp_data['eventStatus'] = $thold_data['thold_alert'] + 1; $thold_snmp_data['eventRealertStatus'] = $ra ? $breach_up ? 3 : 2 : 1; $thold_snmp_data['eventNotificationType'] = ($ra ? ST_NOTIFYRA : ST_NOTIFYAL) + 1; $thold_snmp_data['eventFailCount'] = $thold_data['thold_fail_count']; $thold_snmp_data['eventFailDuration'] = $thold_data['thold_fail_count'] * $cacti_polling_interval; $thold_snmp_data['eventFailDurationTrigger'] = $trigger * $cacti_polling_interval; $thold_snmp_data['eventDescription'] = str_replace(array('<FAIL_COUNT>', '<FAIL_DURATION>'), array($thold_snmp_data['eventFailCount'], $thold_snmp_data['eventFailDuration']), $thold_snmp_data['eventDescription']); thold_snmptrap($thold_snmp_data); } thold_log(array('type' => 0, 'time' => time(), 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], 'threshold_value' => $breach_up ? $thold_data['thold_hi'] : $thold_data['thold_low'], 'current' => $thold_data['lastread'], 'status' => $ra ? ST_NOTIFYRA : ST_NOTIFYAL, 'description' => $subject, 'emails' => $alert_emails)); } db_execute('UPDATE thold_data SET thold_alert=' . $thold_data['thold_alert'] . ', thold_fail_count=' . $thold_data['thold_fail_count'] . ",\n\t\t\t\tthold_warning_fail_count=0\n\t\t\t\tWHERE id=" . $thold_data['id']); } elseif ($warning_breach_up || $warning_breach_down) { $notify = false; thold_debug('Threshold HI / Low Warning check breached HI:' . $thold_data['thold_warning_hi'] . ' LOW:' . $thold_data['thold_warning_low'] . ' VALUE:' . $thold_data['lastread']); $thold_data['thold_warning_fail_count']++; $thold_data['thold_alert'] = $warning_breach_up ? STAT_HI : STAT_LO; /* re-alert? */ $ra = $thold_data['thold_warning_fail_count'] > $warning_trigger && $thold_data['repeat_alert'] != 0 && $thold_data['thold_warning_fail_count'] % $thold_data['repeat_alert'] == 0; if ($thold_data['thold_warning_fail_count'] == $warning_trigger || $ra) { $notify = true; } $subject = ($notify ? 'WARNING: ' : 'TRIGGER: ') . $thold_data['name'] . ($thold_show_datasource ? " [{$name}]" : '') . ' ' . ($ra ? 'is still' : 'went') . ' ' . ($warning_breach_up ? 'above' : 'below') . ' threshold of ' . ($warning_breach_up ? $thold_data['thold_warning_hi'] : $thold_data['thold_warning_low']) . ' with ' . $thold_data['lastread']; if ($notify) { thold_debug('Alerting is necessary'); if ($logset == 1) { logger($thold_data['name'], $ra ? 'rewarning' : 'warning', $warning_breach_up ? $thold_data['thold_warning_hi'] : $thold_data['thold_warning_low'], $thold_data['lastread'], $warning_trigger, $thold_data['thold_warning_fail_count'], $url); } if (trim($warning_emails) != '') { thold_mail($warning_emails, '', $subject, $warn_msg, $file_array); } if ($thold_snmp_traps && $thold_snmp_warning_traps) { $thold_snmp_data['eventClass'] = 2; $thold_snmp_data['eventSeverity'] = $thold_data['snmp_event_warning_severity']; $thold_snmp_data['eventStatus'] = $thold_data['thold_alert'] + 1; $thold_snmp_data['eventRealertStatus'] = $ra ? $warning_breach_up ? 3 : 2 : 1; $thold_snmp_data['eventNotificationType'] = ($ra ? ST_NOTIFYRA : ST_NOTIFYWA) + 1; $thold_snmp_data['eventFailCount'] = $thold_data['thold_warning_fail_count']; $thold_snmp_data['eventFailDuration'] = $thold_data['thold_warning_fail_count'] * $cacti_polling_interval; $thold_snmp_data['eventFailDurationTrigger'] = $warning_trigger * $cacti_polling_interval; $thold_snmp_data['eventDescription'] = str_replace(array('<FAIL_COUNT>', '<FAIL_DURATION>'), array($thold_snmp_data['eventFailCount'], $thold_snmp_data['eventFailDuration']), $thold_snmp_data['eventDescription']); thold_snmptrap($thold_snmp_data); } thold_log(array('type' => 0, 'time' => time(), 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], 'threshold_value' => $warning_breach_up ? $thold_data['thold_warning_hi'] : $thold_data['thold_warning_low'], 'current' => $thold_data['lastread'], 'status' => $ra ? ST_NOTIFYRA : ST_NOTIFYWA, 'description' => $subject, 'emails' => $alert_emails)); } elseif ($thold_data['thold_warning_fail_count'] >= $warning_trigger && $thold_data['thold_fail_count'] >= $trigger) { $subject = 'ALERT -> WARNING: ' . $thold_data['name'] . ($thold_show_datasource ? " [{$name}]" : '') . ' Changed to Warning Threshold with Value ' . $thold_data['lastread']; if (trim($alert_emails) != '') { thold_mail($alert_emails, '', $subject, $warn_msg, $file_array); } if ($thold_snmp_traps && $thold_snmp_warning_traps) { $thold_snmp_data['eventClass'] = 2; $thold_snmp_data['eventSeverity'] = $thold_data['snmp_event_warning_severity']; $thold_snmp_data['eventStatus'] = $thold_data['thold_alert'] + 1; $thold_snmp_data['eventNotificationType'] = ST_NOTIFYAW + 1; $thold_snmp_data['eventFailCount'] = $thold_data['thold_warning_fail_count']; $thold_snmp_data['eventFailDuration'] = $thold_data['thold_warning_fail_count'] * $cacti_polling_interval; $thold_snmp_data['eventFailDurationTrigger'] = $trigger * $cacti_polling_interval; $thold_snmp_data['eventDescription'] = str_replace(array('<FAIL_COUNT>', '<FAIL_DURATION>'), array($thold_snmp_data['eventFailCount'], $thold_snmp_data['eventFailDuration']), $thold_snmp_data['eventDescription']); thold_snmptrap($thold_snmp_data); } thold_log(array('type' => 0, 'time' => time(), 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], 'threshold_value' => $warning_breach_up ? $thold_data['thold_warning_hi'] : $thold_data['thold_warning_low'], 'current' => $thold_data['lastread'], 'status' => ST_NOTIFYAW, 'description' => $subject, 'emails' => $alert_emails)); } db_execute('UPDATE thold_data SET thold_alert=' . $thold_data['thold_alert'] . ', thold_warning_fail_count=' . $thold_data['thold_warning_fail_count'] . ', thold_fail_count=0 WHERE id=' . $thold_data['id']); } else { thold_debug('Threshold HI / Low check is normal HI:' . $thold_data['thold_hi'] . ' LOW:' . $thold_data['thold_low'] . ' VALUE:' . $thold_data['lastread']); /* if we were at an alert status before */ if ($alertstat != 0) { $subject = 'NORMAL: ' . $thold_data['name'] . ($thold_show_datasource ? " [{$name}]" : '') . ' Restored to Normal Threshold with Value ' . $thold_data['lastread']; db_execute("UPDATE thold_data\n\t\t\t\t\tSET thold_alert=0, \n\t\t\t\t\tthold_fail_count=0, \n\t\t\t\t\tthold_warning_fail_count=0\n\t\t\t\t\tWHERE id=" . $thold_data['id']); if ($thold_data['thold_warning_fail_count'] >= $warning_trigger && $thold_data['restored_alert'] != 'on') { if ($logset == 1) { logger($thold_data['name'], 'ok', 0, $thold_data['lastread'], $warning_trigger, $thold_data['thold_warning_fail_count'], $url); } if (trim($warning_emails) != '' && $thold_data['restored_alert'] != 'on') { thold_mail($warning_emails, '', $subject, $warn_msg, $file_array); } if ($thold_snmp_traps && $thold_snmp_normal_traps) { $thold_snmp_data['eventClass'] = 1; $thold_snmp_data['eventSeverity'] = 1; $thold_snmp_data['eventStatus'] = 1; $thold_snmp_data['eventNotificationType'] = ST_NOTIFYRS + 1; thold_snmptrap($thold_snmp_data); } thold_log(array('type' => 0, 'time' => time(), 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], 'threshold_value' => '', 'current' => $thold_data['lastread'], 'status' => ST_NOTIFYRS, 'description' => $subject, 'emails' => $warning_emails)); } elseif ($thold_data['thold_fail_count'] >= $trigger && $thold_data['restored_alert'] != 'on') { if ($logset == 1) { logger($thold_data['name'], 'ok', 0, $thold_data['lastread'], $trigger, $thold_data['thold_fail_count'], $url); } if (trim($alert_emails) != '' && $thold_data['restored_alert'] != 'on') { thold_mail($alert_emails, '', $subject, $alert_msg, $file_array); } if ($thold_snmp_traps && $thold_snmp_normal_traps) { $thold_snmp_data['eventClass'] = 1; $thold_snmp_data['eventSeverity'] = 1; $thold_snmp_data['eventStatus'] = 1; $thold_snmp_data['eventNotificationType'] = ST_NOTIFYRS + 1; thold_snmptrap($thold_snmp_data); } thold_log(array('type' => 0, 'time' => time(), 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], 'threshold_value' => '', 'current' => $thold_data['lastread'], 'status' => ST_NOTIFYRS, 'description' => $subject, 'emails' => $alert_emails)); } } } break; case 1: /* baseline */ $bl_alert_prev = $thold_data['bl_alert']; $bl_count_prev = $thold_data['bl_fail_count']; $bl_fail_trigger = $thold_data['bl_fail_trigger'] == '' ? $alert_bl_trigger : $thold_data['bl_fail_trigger']; $thold_data['bl_alert'] = thold_check_baseline($local_data_id, $name, $thold_data['lastread'], $thold_data); switch ($thold_data['bl_alert']) { case -2: /* exception is active, Future Release 'todo' */ break; case -1: /* reference value not available, Future Release 'todo' */ break; case 0: /* all clear */ /* if we were at an alert status before */ if ($alertstat != 0) { thold_debug('Threshold Baseline check is normal'); if ($thold_data['bl_fail_count'] >= $bl_fail_trigger && $thold_data['restored_alert'] != 'on') { thold_debug('Threshold Baseline check returned to normal'); if ($logset == 1) { logger($thold_data['name'], 'ok', 0, $thold_data['lastread'], $thold_data['bl_fail_trigger'], $thold_data['bl_fail_count'], $url); } $subject = 'NORMAL: ' . $thold_data['name'] . ($thold_show_datasource ? " [{$name}]" : '') . ' restored to normal threshold with value ' . $thold_data['lastread']; if (trim($alert_emails) != '') { thold_mail($alert_emails, '', $subject, $alert_msg, $file_array); } if ($thold_snmp_traps && $thold_snmp_normal_traps) { $thold_snmp_data['eventClass'] = 1; $hold_snmp_data['eventSeverity'] = 1; $thold_snmp_data['eventStatus'] = 1; $thold_snmp_data['eventNotificationType'] = ST_NOTIFYRS + 1; thold_snmptrap($thold_snmp_data); } thold_log(array('type' => 1, 'time' => time(), 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], 'threshold_value' => '', 'current' => $thold_data['lastread'], 'status' => ST_NOTIFYRA, 'description' => $subject, 'emails' => $alert_emails)); } } $thold_data['bl_fail_count'] = 0; break; case 1: /* value is below calculated threshold */ /* value is below calculated threshold */ case 2: /* value is above calculated threshold */ $thold_data['bl_fail_count']++; $breach_up = $thold_data['bl_alert'] == STAT_HI; $breach_down = $thold_data['bl_alert'] == STAT_LO; thold_debug('Threshold Baseline check breached'); /* re-alert? */ $ra = $thold_data['bl_fail_count'] > $bl_fail_trigger && $thold_data['bl_fail_count'] % ($thold_data['repeat_alert'] == '' ? $realert : $thold_data['repeat_alert']) == 0; if ($thold_data['bl_fail_count'] == $bl_fail_trigger || $ra) { thold_debug('Alerting is necessary'); $subject = 'ALERT: ' . $thold_data['name'] . ($thold_show_datasource ? " [{$name}]" : '') . ' ' . ($ra ? 'is still' : 'went') . ' ' . ($breach_up ? 'above' : 'below') . ' calculated baseline threshold ' . ($breach_up ? $thold_data['thold_hi'] : $thold_data['thold_low']) . ' with ' . $thold_data['lastread']; if ($logset == 1) { logger($thold_data['name'], $ra ? 'realert' : 'alert', $breach_up ? $thold_data['thold_hi'] : $thold_data['thold_low'], $thold_data['lastread'], $thold_data['bl_fail_trigger'], $thold_data['bl_fail_count'], $url); } if (trim($alert_emails) != '') { thold_mail($alert_emails, '', $subject, $alert_msg, $file_array); } if ($thold_snmp_traps) { $thold_snmp_data['eventClass'] = 3; $thold_snmp_data['eventSeverity'] = $thold_data['snmp_event_severity']; $thold_snmp_data['eventStatus'] = $thold_data['bl_alert'] + 1; $thold_snmp_data['eventRealertStatus'] = $ra ? $breach_up ? 3 : 2 : 1; $thold_snmp_data['eventNotificationType'] = ($ra ? ST_NOTIFYRA : ST_NOTIFYAL) + 1; $thold_snmp_data['eventFailCount'] = $thold_data['bl_fail_count']; $thold_snmp_data['eventFailDuration'] = $thold_data['bl_fail_count'] * $cacti_polling_interval; $thold_snmp_data['eventFailCountTrigger'] = $bl_fail_trigger; $thold_snmp_data['eventDescription'] = str_replace(array('<FAIL_COUNT>', '<FAIL_DURATION>'), array($thold_snmp_data['eventFailCount'], $thold_snmp_data['eventFailDuration']), $thold_snmp_data['eventDescription']); thold_snmptrap($thold_snmp_data); } thold_log(array('type' => 1, 'time' => time(), 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], 'threshold_value' => $breach_up ? $thold_data['thold_hi'] : $thold_data['thold_low'], 'current' => $thold_data['lastread'], 'status' => $ra ? ST_NOTIFYRA : ST_NOTIFYAL, 'description' => $subject, 'emails' => $alert_emails)); } else { thold_log(array('type' => 1, 'time' => time(), 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], 'threshold_value' => $breach_up ? $thold_data['thold_hi'] : $thold_data['thold_low'], 'current' => $thold_data['lastread'], 'status' => ST_TRIGGERA, 'description' => $subject, 'emails' => $alert_emails)); } break; } db_execute("UPDATE thold_data \n\t\t\tSET thold_alert=0, \n\t\t\tthold_fail_count=0,\n\t\t\tbl_alert='" . $thold_data['bl_alert'] . "',\n\t\t\tbl_fail_count='" . $thold_data['bl_fail_count'] . "',\n\t\t\tthold_low='" . $thold_data['thold_low'] . "',\n\t\t\tthold_hi='" . $thold_data['thold_hi'] . "',\n\t\t\tbl_thold_valid='" . $thold_data['bl_thold_valid'] . "'\n\t\t\tWHERE id=" . $thold_data['id']); break; case 2: /* time based */ if ($thold_data['lastread'] != '') { $breach_up = $thold_data['time_hi'] != '' && $thold_data['lastread'] > $thold_data['time_hi']; $breach_down = $thold_data['time_low'] != '' && $thold_data['lastread'] < $thold_data['time_low']; $warning_breach_up = $thold_data['time_warning_hi'] != '' && $thold_data['lastread'] > $thold_data['time_warning_hi']; $warning_breach_down = $thold_data['time_warning_low'] != '' && $thold_data['lastread'] < $thold_data['time_warning_low']; } else { $breach_up = $breach_down = $warning_breach_up = $warning_breach_down = false; } $step = db_fetch_cell('SELECT rrd_step FROM data_template_data WHERE local_data_id = ' . $local_data_id, FALSE); /* alerts */ $trigger = $thold_data['time_fail_trigger']; $time = time() - $thold_data['time_fail_length'] * $step; $failures = db_fetch_cell('SELECT count(id) FROM plugin_thold_log WHERE threshold_id=' . $thold_data['id'] . ' AND status IN (' . ST_TRIGGERA . ',' . ST_NOTIFYRA . ',' . ST_NOTIFYAL . ') AND time>' . $time); /* warnings */ $warning_trigger = $thold_data['time_warning_fail_trigger']; $warning_time = time() - $thold_data['time_warning_fail_length'] * $step; $warning_failures = db_fetch_cell('SELECT count(id) FROM plugin_thold_log WHERE threshold_id=' . $thold_data['id'] . ' AND status IN (' . ST_NOTIFYWA . ',' . ST_TRIGGERW . ') AND time>' . $warning_time) + $failures; if ($breach_up || $breach_down) { $notify = false; thold_debug('Threshold Time Based check breached HI:' . $thold_data['time_hi'] . ' LOW:' . $thold_data['time_low'] . ' VALUE:' . $thold_data['lastread']); $thold_data['thold_alert'] = $breach_up ? STAT_HI : STAT_LO; $thold_data['thold_fail_count'] = $failures; /* we should only re-alert X minutes after last email, not every 5 pollings, etc... re-alert? */ $realerttime = ($thold_data['repeat_alert'] - 1) * $step; $lastemailtime = db_fetch_cell('SELECT time FROM plugin_thold_log WHERE threshold_id=' . $thold_data['id'] . ' AND status IN (' . ST_NOTIFYRA . ',' . ST_NOTIFYAL . ') ORDER BY time DESC LIMIT 1', FALSE); $ra = $failures > $trigger && $thold_data['repeat_alert'] && !empty($lastemailtime) && $lastemailtime + $realerttime <= time(); $failures++; thold_debug("Alert Time:'{$time}', Alert Trigger:'{$trigger}', Alert Failures:'{$failures}', RealertTime:'{$realerttime}', LastTime:'{$lastemailtime}', RA:'{$ra}', Diff:'" . ($realerttime + $lastemailtime) . "'<'" . time() . "'"); if ($failures == $trigger || $ra) { $notify = true; } $subject = ($notify ? 'ALERT: ' : 'TRIGGER: ') . $thold_data['name'] . ($thold_show_datasource ? " [{$name}]" : '') . ' ' . ($failures > $trigger ? 'is still' : 'went') . ' ' . ($breach_up ? 'above' : 'below') . ' threshold of ' . ($breach_up ? $thold_data['time_hi'] : $thold_data['time_low']) . ' with ' . $thold_data['lastread']; if ($notify) { thold_debug('Alerting is necessary'); if ($logset == 1) { logger($thold_data['name'], $failures > $trigger ? 'realert' : 'alert', $breach_up ? $thold_data['time_hi'] : $thold_data['time_low'], $thold_data['lastread'], $trigger, $failures, $url); } if (trim($alert_emails) != '') { thold_mail($alert_emails, '', $subject, $alert_msg, $file_array); } if ($thold_snmp_traps) { $thold_snmp_data['eventClass'] = 3; $thold_snmp_data['eventSeverity'] = $thold_data['snmp_event_severity']; $thold_snmp_data['eventStatus'] = $thold_data['thold_alert'] + 1; $thold_snmp_data['eventRealertStatus'] = $ra ? $breach_up ? 3 : 2 : 1; $thold_snmp_data['eventNotificationType'] = ($failures > $trigger ? ST_NOTIFYAL : ST_NOTIFYRA) + 1; $thold_snmp_data['eventFailCount'] = $failures; $thold_snmp_data['eventFailCountTrigger'] = $trigger; $thold_snmp_data['eventDescription'] = str_replace('<FAIL_COUNT>', $thold_snmp_data['eventFailCount'], $thold_snmp_data['eventDescription']); thold_snmptrap($thold_snmp_data); } thold_log(array('type' => 2, 'time' => time(), 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], 'threshold_value' => $breach_up ? $thold_data['time_hi'] : $thold_data['time_low'], 'current' => $thold_data['lastread'], 'status' => $failures > $trigger ? ST_NOTIFYAL : ST_NOTIFYRA, 'description' => $subject, 'emails' => $alert_emails)); } else { thold_log(array('type' => 2, 'time' => time(), 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], 'threshold_value' => $breach_up ? $thold_data['time_hi'] : $thold_data['time_low'], 'current' => $thold_data['lastread'], 'status' => ST_TRIGGERA, 'description' => $subject, 'emails' => $alert_emails)); } db_execute('UPDATE thold_data SET thold_alert=' . $thold_data['thold_alert'] . ",\n\t\t\t\tthold_fail_count={$failures}\n\t\t\t\tWHERE id=" . $thold_data['id']); } elseif ($warning_breach_up || $warning_breach_down) { $notify = false; $thold_data['thold_alert'] = $warning_breach_up ? STAT_HI : STAT_LO; $thold_data['thold_warning_fail_count'] = $warning_failures; /* we should only re-alert X minutes after last email, not every 5 pollings, etc... re-alert? */ $realerttime = ($thold_data['time_warning_fail_length'] - 1) * $step; $lastemailtime = db_fetch_cell('SELECT time FROM plugin_thold_log WHERE threshold_id=' . $thold_data['id'] . ' AND status IN (' . ST_NOTIFYRA . ',' . ST_NOTIFYWA . ') ORDER BY time DESC LIMIT 1', FALSE); $ra = $warning_failures > $warning_trigger && $thold_data['time_warning_fail_length'] && !empty($lastemailtime) && $lastemailtime + $realerttime <= time(); $warning_failures++; thold_debug("Warn Time:'{$warning_time}', Warn Trigger:'{$warning_trigger}', Warn Failures:'{$warning_failures}', RealertTime:'{$realerttime}', LastTime:'{$lastemailtime}', RA:'{$ra}', Diff:'" . ($realerttime + $lastemailtime) . "'<'" . time() . "'"); if ($warning_failures == $warning_trigger || $ra) { $notify = true; } $subject = ($notify ? 'WARNING: ' : 'TRIGGER: ') . $thold_data['name'] . ($thold_show_datasource ? " [{$name}]" : '') . ' ' . ($warning_failures > $warning_trigger ? 'is still' : 'went') . ' ' . ($warning_breach_up ? 'above' : 'below') . ' threshold of ' . ($warning_breach_up ? $thold_data['time_warning_hi'] : $thold_data['time_warning_low']) . ' with ' . $thold_data['lastread']; if ($notify) { if ($logset == 1) { logger($thold_data['name'], $warning_failures > $warning_trigger ? 'rewarning' : 'warning', $warning_breach_up ? $thold_data['time_warning_hi'] : $thold_data['time_warning_low'], $thold_data['lastread'], $warning_trigger, $warning_failures, $url); } if (trim($alert_emails) != '') { thold_mail($warning_emails, '', $subject, $warn_msg, $file_array); } if ($thold_snmp_traps && $thold_snmp_warning_traps) { $thold_snmp_data['eventClass'] = 2; $thold_snmp_data['eventSeverity'] = $thold_data['snmp_event_warning_severity']; $thold_snmp_data['eventStatus'] = $thold_data['thold_alert'] + 1; $thold_snmp_data['eventRealertStatus'] = $ra ? $warning_breach_up ? 3 : 2 : 1; $thold_snmp_data['eventNotificationType'] = ($warning_failures > $warning_trigger ? ST_NOTIFYRA : ST_NOTIFYWA) + 1; $thold_snmp_data['eventFailCount'] = $warning_failures; $thold_snmp_data['eventFailCountTrigger'] = $warning_trigger; $thold_snmp_data['eventDescription'] = str_replace('<FAIL_COUNT>', $thold_snmp_data['eventFailCount'], $thold_snmp_data['eventDescription']); thold_snmptrap($thold_snmp_data); } thold_log(array('type' => 2, 'time' => time(), 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], 'threshold_value' => $breach_up ? $thold_data['time_hi'] : $thold_data['time_low'], 'current' => $thold_data['lastread'], 'status' => $warning_failures > $warning_trigger ? ST_NOTIFYRA : ST_NOTIFYWA, 'description' => $subject, 'emails' => $alert_emails)); } elseif ($alertstat != 0 && $warning_failures < $warning_trigger && $failures < $trigger) { $subject = 'ALERT -> WARNING: ' . $thold_data['name'] . ($thold_show_datasource ? " [{$name}]" : '') . ' restored to warning threshold with value ' . $thold_data['lastread']; thold_log(array('type' => 2, 'time' => time(), 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], 'threshold_value' => $warning_breach_up ? $thold_data['time_hi'] : $thold_data['time_low'], 'current' => $thold_data['lastread'], 'status' => ST_NOTIFYAW, 'description' => $subject, 'emails' => $alert_emails)); } else { thold_log(array('type' => 2, 'time' => time(), 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], 'threshold_value' => $warning_breach_up ? $thold_data['time_hi'] : $thold_data['time_low'], 'current' => $thold_data['lastread'], 'status' => ST_TRIGGERW, 'description' => $subject, 'emails' => $warning_emails)); } db_execute('UPDATE thold_data SET thold_alert=' . $thold_data['thold_alert'] . ",\n\t\t\t\tthold_warning_fail_count={$warning_failures},\n\t\t\t\tthold_fail_count={$failures}\n\t\t\t\tWHERE id=" . $thold_data['id']); } else { thold_debug('Threshold Time Based check is normal HI:' . $thold_data['time_hi'] . ' LOW:' . $thold_data['time_low'] . ' VALUE:' . $thold_data['lastread']); if ($alertstat != 0 && $warning_failures < $warning_trigger && $thold_data['restored_alert'] != 'on') { if ($logset == 1) { logger($thold_data['name'], 'ok', 0, $thold_data['lastread'], $warning_trigger, $thold_data['thold_warning_fail_count'], $url); } $subject = 'NORMAL: ' . $thold_data['name'] . ($thold_show_datasource ? " [{$name}]" : '') . ' restored to normal threshold with value ' . $thold_data['lastread']; if (trim($warning_emails) != '' && $thold_data['restored_alert'] != 'on') { thold_mail($warning_emails, '', $subject, $alert_msg, $file_array); } if ($thold_snmp_traps && $thold_snmp_normal_traps) { $thold_snmp_data['eventClass'] = 1; $thold_snmp_data['eventSeverity'] = 1; $thold_snmp_data['eventStatus'] = 1; $thold_snmp_data['eventNotificationType'] = ST_NOTIFYRS + 1; thold_snmptrap($thold_snmp_data); } thold_log(array('type' => 2, 'time' => time(), 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], 'threshold_value' => '', 'current' => $thold_data['lastread'], 'status' => ST_NOTIFYRS, 'description' => $subject, 'emails' => $warning_emails)); db_execute("UPDATE thold_data\n\t\t\t\t\tSET thold_alert=0, \n\t\t\t\t\tthold_warning_fail_count={$warning_failures}, \n\t\t\t\t\tthold_fail_count={$failures}\n\t\t\t\t\tWHERE id=" . $thold_data['id']); } elseif ($alertstat != 0 && $failures < $trigger && $thold_data['restored_alert'] != 'on') { if ($logset == 1) { logger($thold_data['name'], 'ok', 0, $thold_data['lastread'], $trigger, $thold_data['thold_fail_count'], $url); } $subject = 'NORMAL: ' . $thold_data['name'] . ($thold_show_datasource ? " [{$name}]" : '') . ' restored to warning threshold with value ' . $thold_data['lastread']; if (trim($alert_emails) != '' && $thold_data['restored_alert'] != 'on') { thold_mail($alert_emails, '', $subject, $alert_msg, $file_array); } if ($thold_snmp_traps && $thold_snmp_normal_traps) { $thold_snmp_data['eventClass'] = 1; $thold_snmp_data['eventSeverity'] = 1; $thold_snmp_data['eventStatus'] = 1; $thold_snmp_data['eventNotificationType'] = ST_NOTIFYRS + 1; thold_snmptrap($thold_snmp_data); } thold_log(array('type' => 2, 'time' => time(), 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], 'threshold_value' => '', 'current' => $thold_data['lastread'], 'status' => ST_NOTIFYRS, 'description' => $subject, 'emails' => $alert_emails)); db_execute("UPDATE thold_data\n\t\t\t\t\tSET thold_alert=0, \n\t\t\t\t\tthold_warning_fail_count={$warning_failures}, \n\t\t\t\t\tthold_fail_count={$failures}\n\t\t\t\t\tWHERE id=" . $thold_data['id']); } else { db_execute("UPDATE thold_data\n\t\t\t\t\tSET thold_fail_count={$failures},\n\t\t\t\t\tthold_warning_fail_count={$warning_failures}\n\t\t\t\t\tWHERE id=" . $thold_data['id']); } } break; } }
function draw_menu($user_menu = "") { global $colors, $config, $user_auth_realms, $user_auth_realm_filenames, $menu; if (strlen($user_menu == 0)) { $user_menu = $menu; } /* list all realms that this user has access to */ if (read_config_option("auth_method") != 0) { $user_realms = db_fetch_assoc("select realm_id from user_auth_realm where user_id=" . $_SESSION["sess_user_id"]); $user_realms = array_rekey($user_realms, "realm_id", "realm_id"); }else{ $user_realms = $user_auth_realms; } $first_ul = true; /* loop through each header */ while (list($header_name, $header_array) = each($user_menu)) { /* pass 1: see if we are allowed to view any children */ $show_header_items = false; while (list($item_url, $item_title) = each($header_array)) { $current_realm_id = (isset($user_auth_realm_filenames{basename($item_url)}) ? $user_auth_realm_filenames{basename($item_url)} : 0); if ((isset($user_realms[$current_realm_id])) || (!isset($user_auth_realm_filenames{basename($item_url)}))) { $show_header_items = true; } } reset($header_array); if ($show_header_items == true) { if (!$first_ul) { print "</ul></div>"; }else{ $first_ul = false; } $id = clean_up_name(strtolower($header_name)); $ani = "onClick='changeMenuState(\"" . $id . "\")'"; ?> <script type="text/javascript"> <!-- $().ready(function() { changeMenuState('<?php print $id;?>', true); }); --> </script> <?php print "<div id='mm_$id' onMouseDown='return false' class='menuMain nw' $ani>$header_name</div> <div> <ul id='ul_$id' class='menuSubMain'>"; } /* pass 2: loop through each top level item and render it */ while (list($item_url, $item_title) = each($header_array)) { $current_realm_id = (isset($user_auth_realm_filenames{basename($item_url)}) ? $user_auth_realm_filenames{basename($item_url)} : 0); /* if this item is an array, then it contains sub-items. if not, is just the title string and needs to be displayed */ if (is_array($item_title)) { $i = 0; if ((isset($user_realms[$current_realm_id])) || (!isset($user_auth_realm_filenames{basename($item_url)}))) { /* if the current page exists in the sub-items array, draw each sub-item */ if (array_key_exists(basename($_SERVER["PHP_SELF"]), $item_title) == true) { $draw_sub_items = true; }else{ $draw_sub_items = false; } while (list($item_sub_url, $item_sub_title) = each($item_title)) { $item_sub_url = CACTI_URL_PATH . $item_sub_url; /* indent sub-items */ if ($i > 0) { $prepend_string = "--- "; }else{ $prepend_string = ""; } /* do not put a line between each sub-item */ if (($i == 0) || ($draw_sub_items == false)) { $background = CACTI_URL_PATH . "images/menu_line.gif"; }else{ $background = ""; } /* draw all of the sub-items as selected for ui grouping reasons. we can use the 'bold' or 'not bold' to distinguish which sub-item is actually selected */ if ((basename($_SERVER["PHP_SELF"]) == basename($item_sub_url)) || ($draw_sub_items)) { $td_class = "textMenuItemSelected"; }else{ $td_class = "textMenuItem"; } /* always draw the first item (parent), only draw the children if we are viewing a page that is contained in the sub-items array */ if (($i == 0) || ($draw_sub_items)) { if (basename($_SERVER["PHP_SELF"]) == basename($item_sub_url)) { print "<li class='menuSubMainSelected'><a href='$item_sub_url'>$prepend_string$item_sub_title</a></li>"; }else{ print "<li><a href='$item_sub_url'>$prepend_string$item_sub_title</a></li>"; } } $i++; } } }else{ if ((isset($user_realms[$current_realm_id])) || (!isset($user_auth_realm_filenames{basename($item_url)}))) { /* draw normal (non sub-item) menu item */ $item_url = CACTI_URL_PATH . $item_url; if (basename($_SERVER["PHP_SELF"]) == basename($item_url)) { print "<li class='menuSubMainSelected'><a href='$item_url'>$item_title</a></li>"; }else{ print "<li><a href='$item_url'>$item_title</a></li>"; } } } } } print "</ul></div>"; }