*******************************************************************************/ // Update automatically 'alert_base_url' if not set and if we are called from the browser // so that check-thold can pick it up if (isset($_SERVER["HTTP_HOST"]) && isset($_SERVER["PHP_SELF"]) && read_config_option("alert_base_url") == "") { $dir = dirname($_SERVER["PHP_SELF"]); if (strpos($dir, '/plugins/') !== false) $dir = substr($dir, 0, strpos($dir, '/plugins/')); db_execute("replace into settings (name,value) values ('alert_base_url', '" . ("http://" . $_SERVER["HTTP_HOST"] . $dir . "/") . "')"); /* reset local settings cache so the user sees the new settings */ kill_session_var("sess_config_array"); } function thold_check_threshold ($rra_id, $data_id, $name, $currentval, $cdef) { global $config; include_once($config["base_path"] . "/plugins/thold/thold_functions.php"); // Maybe set an option for these? $show = true; $debug = false; /* Pull a few default settings */ $global_alert_address = read_config_option("alert_email"); $global_notify_enabled = (read_config_option("alert_notify_default") == "on"); $global_bl_notify_enabled = (read_config_option("alert_notify_bl") == "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"); $alert_exempt = read_config_option("alert_exempt"); $httpurl = read_config_option("alert_base_url"); $thold_show_datasource = read_config_option("thold_show_datasource"); $thold_send_text_only = read_config_option("thold_send_text_only"); $thold_alert_text = read_config_option('thold_alert_text'); // Remove this after adding an option for it $thold_show_datasource = true; /* check for exemptions */ $weekday=date("l"); if (($weekday == "Saturday" || $weekday == "Sunday") && $alert_exempt == "on") { 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=" . $rra_id . " order by id LIMIT 1"); if (isset($t[0]["name_cache"])) $desc = $t[0]["name_cache"]; else return; /* Get all the info about the item from the database */ $item = db_fetch_assoc("select * from thold_data where thold_enabled='on' AND data_id = " . $data_id); /* Return if the item doesn't exist, which means its disabled */ if (!isset($item[0])) return; $item = $item[0]; if ($cdef != 0) $currentval = thold_build_cdef($cdef, $currentval, $rra_id, $data_id); $currentval = round($currentval, 4); $trigger = ($item["thold_fail_trigger"] == "" ? $alert_trigger : $item["thold_fail_trigger"]); if ($show) { print "Checking Threshold : \"$desc\"\n"; print " Data Source : " . $name; } $grapharr = db_fetch_assoc("SELECT DISTINCT local_graph_id FROM graph_templates_item WHERE task_item_id=" . $data_id); $graph_id = $grapharr[0]['local_graph_id']; $breach_up = ($item["thold_hi"] != "" && $currentval > $item["thold_hi"]); $breach_down = ($item["thold_low"] != "" && $currentval < $item["thold_low"]); $alertstat = $item["thold_alert"]; $item["thold_alert"] = ($breach_up ? 2 : ($breach_down ? 1 : 0)); // Make sure the alert text has been set if (!isset($thold_alert_text) || $thold_alert_text == '') { $thold_alert_text = "An alert has been issued that requires your attention.

Host: ()
URL:
Message:

"; } $hostname = db_fetch_assoc('SELECT description, hostname from host WHERE id = ' . $item['host_id']); $hostname = $hostname[0]; // Do some replacement of variables $thold_alert_text = str_replace('', $hostname['description'], $thold_alert_text); $thold_alert_text = str_replace('', $hostname['hostname'], $thold_alert_text); $thold_alert_text = str_replace('