print "\r\n\t\t<td></td>\n\r\n\t\t</tr>\r\n\t\t</table>\n"; } elseif (sizeof($template_data_rrds) == 1) { $_GET["view_rrd"] = $template_data_rrds[0]["id"]; } } //---------------------- // Data Source Item Form //---------------------- $thold_item_data = db_fetch_assoc("SELECT * \r\n\tFROM thold_data \r\n\tWHERE data_id=" . $_GET["view_rrd"]); $thold_item_data = count($thold_item_data) > 0 ? $thold_item_data[0] : $thold_item_data; $thold_item_data_cdef = isset($thold_item_data['cdef']) ? $thold_item_data['cdef'] : 0; html_start_box("", "100%", $colors["header"], "3", "center", ""); //------------------------ // Data Source Item header //------------------------ print "\t<tr>\r\n\t<td colspan=2 bgcolor='#" . $colors["header"] . "' class='textHeaderDark'>\r\n\t<strong>Data Source Item</strong> [" . (isset($template_rrd) ? $template_rrd["data_source_name"] : "") . "] " . " - <strong>Current value: </strong>[" . get_current_value($rra, $ds, $thold_item_data_cdef) . "]</td>\r\n\t</tr>\n"; $send_notification_array = array(); $users = db_fetch_assoc("SELECT plugin_thold_contacts.id, plugin_thold_contacts.data, \r\n\tplugin_thold_contacts.type, user_auth.full_name \r\n\tFROM plugin_thold_contacts, user_auth \r\n\tWHERE user_auth.id=plugin_thold_contacts.user_id \r\n\tAND plugin_thold_contacts.data!='' \r\n\tORDER BY user_auth.full_name ASC, plugin_thold_contacts.type ASC"); if (!empty($users)) { foreach ($users as $user) { $send_notification_array[$user['id']] = $user['full_name'] . ' - ' . ucfirst($user['type']); } } if (isset($thold_item_data['id'])) { $sql = 'SELECT contact_id as id FROM plugin_thold_threshold_contact WHERE thold_id=' . $thold_item_data['id']; $step = db_fetch_cell('SELECT rrd_step FROM data_template_data WHERE local_data_id = ' . $thold_item_data['rra_id'], FALSE); } else { $sql = 'SELECT contact_id as id FROM plugin_thold_threshold_contact WHERE thold_id=0'; $step = db_fetch_cell('SELECT rrd_step FROM data_template_data WHERE local_data_id = ' . $rra, FALSE); } if ($step == 60) {
function thold_edit() { global $config; if (isset_request_var('id')) { $thold_data = db_fetch_row_prepared('SELECT * FROM thold_data WHERE id = ?', array(get_request_var('id'))); } elseif (isset_request_var('local_data_id') && isset_request_var('local_graph_id') && isset_request_var('host_id') && isset_request_var('data_template_id') && isset_request_var('data_template_rrd_id')) { $thold_data['id'] = '0'; $thold_data['local_data_id'] = get_filter_request_var('local_data_id'); $thold_data['local_graph_id'] = get_filter_request_var('local_graph_id'); $thold_data['data_template_id'] = get_filter_request_var('data_template_id'); $thold_data['host_id'] = get_filter_request_var('host_id'); $thold_data['data_template_rrd_id'] = get_filter_request_var('data_template_rrd_id'); $thold_data['thold_template_id'] = get_filter_request_var('thold_template_id'); } else { exit; } $desc = db_fetch_cell_prepared('SELECT name_cache FROM data_template_data WHERE local_data_id = ? LIMIT 1', array($thold_data['local_data_id'])); $rrdsql = array_rekey(db_fetch_assoc_prepared("SELECT id \n\t\tFROM data_template_rrd \n\t\tWHERE local_data_id = ? ORDER BY id", array($thold_data['local_data_id'])), 'id', 'id'); $grapharr = db_fetch_assoc('SELECT DISTINCT local_graph_id FROM graph_templates_item WHERE task_item_id IN (' . implode(', ', $rrdsql) . ') AND graph_template_id>0'); if (empty($thold_data['local_graph_id'])) { $thold_data['local_graph_id'] = db_fetch_cell_prepared('SELECT gl.id FROM graph_local AS gl INNER JOIN graph_templates_item AS gti ON gl.id=gti.local_graph_id INNER JOIN data_template_rrd AS dtr ON gti.task_item_id=dtr.id WHERE dtr.local_data_id = ? LIMIT 1', array($thold_data['local_data_id'])); } if (empty($thold_data['data_template_rrd_id'])) { $thold_data['data_template_rrd_id'] = db_fetch_cell_prepared('SELECT id FROM data_template_rrd AS dtr WHERE local_data_id = ? LIMIT 1', array($thold_data['local_data_id'])); } $dt_sql = 'SELECT DISTINCT dtr.local_data_id FROM data_template_rrd AS dtr LEFT JOIN graph_templates_item AS gti ON gti.task_item_id=dtr.id LEFT JOIN graph_local AS gl ON gl.id=gti.local_graph_id WHERE gl.id=' . $thold_data['local_graph_id']; $template_data_rrds = db_fetch_assoc("SELECT td.id AS thold_id, dtr.id, dtr.data_source_name, dtr.local_data_id \n\t\tFROM data_template_rrd AS dtr\n\t\tLEFT JOIN thold_data AS td\n\t\tON dtr.id=td.data_template_rrd_id\n\t\tWHERE dtr.local_data_id IN ({$dt_sql}) \n\t\tORDER BY dtr.id"); form_start('thold.php', 'thold'); html_start_box(__('Graph Data'), '100%', '', '3', 'center', ''); ?> <tr> <td class='textArea'> <?php if (isset($banner)) { echo $banner . '<br><br>'; } ?> <?php print __('Data Source Description:'); ?> <br><?php echo $desc; ?> <br><br> <?php print __('Associated Graph (graphs that use this RRD):'); ?> <br> <select name='element'> <?php foreach ($grapharr as $g) { $graph_desc = db_fetch_row_prepared('SELECT local_graph_id, title, title_cache FROM graph_templates_graph WHERE local_graph_id = ?', array($g['local_graph_id'])); echo "<option value='" . $graph_desc['local_graph_id'] . "'"; if ($graph_desc['local_graph_id'] == $thold_data['local_graph_id']) { echo ' selected'; } echo '>' . $graph_desc['local_graph_id'] . ' - ' . $graph_desc['title_cache'] . " </option>\n"; } ?> </select> <br> <br> </td> <td class='textArea'> <img id='graphimage' src='<?php echo htmlspecialchars($config['url_path'] . 'graph_image.php?local_graph_id=' . $thold_data['local_graph_id'] . '&rra_id=0&graph_start=-32400&graph_height=140&graph_width=500'); ?> '> </td> </tr> <?php html_end_box(); $template_rrd = db_fetch_row_prepared('SELECT * FROM data_template_rrd WHERE id = ?', array($thold_data['data_template_rrd_id'])); //----------------------------- // Tabs (if more than one item) //----------------------------- $i = 0; $ds = 0; if (isset($template_data_rrds)) { if (sizeof($template_data_rrds)) { /* draw the data source tabs on the top of the page */ print "<br><div class='tabs'><nav><ul>\n"; foreach ($template_data_rrds as $template_data_rrd) { if ($template_data_rrd['id'] == $thold_data['data_template_rrd_id']) { $ds = $template_data_rrd['data_source_name']; } if (!empty($template_data_rrd['thold_id'])) { $td = db_fetch_row('SELECT * FROM thold_data WHERE id=' . $template_data_rrd['thold_id']); } else { $td = array(); } $cur_setting = ''; if (!sizeof($td)) { $cur_setting .= "<span style='padding-right:4px;'>" . __('N/A') . "</span>"; } else { $cur_setting = '<span style="padding-right:4px;">' . __('Last:') . '</span>' . ($td['lastread'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceDown'>" . thold_format_number($td['lastread'], 4) . "</span>"); if ($td['thold_type'] != 1) { if ($td['thold_warning_fail_trigger'] != 0) { if ($td['thold_warning_hi'] != '') { $cur_setting .= '<span style="padding:4px">' . __('WHi:') . '</span>' . ($td['thold_warning_hi'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceRecovering'>" . thold_format_number($td['thold_warning_hi'], 2) . '</span>'); } if ($td['thold_warning_low'] != '') { $cur_setting .= '<span style="padding:4px">' . __('WLo:') . '</span>' . ($td['thold_warning_low'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceRecovering'>" . thold_format_number($td['thold_warning_low'], 2) . '</span>'); } } if ($td['thold_fail_trigger'] != 0) { if ($td['thold_hi'] != '') { $cur_setting .= '<span style="padding:4px">' . __('AHi:') . '</span>' . ($td['thold_hi'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceRecovering'>" . thold_format_number($td['thold_hi'], 2) . '</span>'); } if ($td['thold_low'] != '') { $cur_setting .= '<span style="padding:4px">' . __('ALo:') . '</span>' . ($td['thold_low'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceRecovering'>" . thold_format_number($td['thold_low'], 2) . '</span>'); } } } else { $cur_setting .= '<span style="padding:4px">' . __('AHi:') . '</span>' . ($td['thold_hi'] == '' ? "<span>" . __('N/A') . "</span>" : "<span clas='deviceRecovering'>" . thold_format_number($td['thold_hi'], 2) . '</span>'); $cur_setting .= '<span style="padding:4px">' . __('ALo:') . '</span>' . ($td['thold_low'] == '' ? "<span>" . __('N/A') . "</span>" : "<span class='deviceRecovering'>" . thold_format_number($td['thold_low'], 2) . '</span>'); $cur_setting .= '<span>' . __('BL: (Up %s %/Down %s %)', $td['bl_pct_up'], $td['bl_pct_down']) . '</span>'; } } if ($template_data_rrd['id'] == $thold_data['data_template_rrd_id']) { $selected = 'selected'; } else { $selected = ''; } if (!empty($template_data_rrd['thold_id'])) { echo "<li class='textEditTitle'><a class='hyperLink {$selected}' href='" . htmlspecialchars('thold.php?action=edit&id=' . $template_data_rrd['thold_id']) . "'>" . $template_data_rrd['data_source_name'] . '<br>' . $cur_setting . '</a></li>'; } else { echo "<li class='textEditTitle'><a class='hyperLink {$selected}' href='" . htmlspecialchars('thold.php?action=edit&local_data_id=' . $template_data_rrd['local_data_id'] . '&data_template_rrd_id=' . $template_data_rrd['id']) . '&local_graph_id=' . $thold_data['local_graph_id'] . '&host_id=' . $thold_data['host_id'] . '&data_template_id=' . $thold_data['data_template_id'] . '&thold_template_id=0' . "'>" . $template_data_rrd['data_source_name'] . '<br>' . $cur_setting . '</a></li>'; } } echo "<li class='textEditTitle'><a class='hyperLink' href='" . htmlspecialchars('thold.php?action=add' . '&local_graph_id=' . $thold_data['local_graph_id'] . '&host_id=' . $thold_data['host_id']) . "'>new thold<br>n/a</a></li>"; print "</ul></nav></div>\n"; } elseif (sizeof($template_data_rrds) == 1) { set_request_var('data_template_rrd_id', $template_data_rrds[0]['id']); } } //---------------------- // Data Source Item Form //---------------------- $thold_data_cdef = isset($thold_data['cdef']) ? $thold_data['cdef'] : 0; if (isset($thold_data['template'])) { $thold_data['template_name'] = db_fetch_cell_prepared('SELECT name FROM thold_template WHERE id = ?', array($thold_data['thold_template_id'])); } $header_text = __('Data Source Item [%s] ' . ' - Current value: [%s]', isset($template_rrd) ? $template_rrd['data_source_name'] : '', get_current_value($thold_data['local_data_id'], $ds, $thold_data_cdef)); html_start_box($header_text, '100%', '', '3', 'center', ''); $send_notification_array = array(); $users = db_fetch_assoc("SELECT plugin_thold_contacts.id, plugin_thold_contacts.data,\n\t\tplugin_thold_contacts.type, user_auth.full_name\n\t\tFROM plugin_thold_contacts, user_auth\n\t\tWHERE user_auth.id=plugin_thold_contacts.user_id\n\t\tAND plugin_thold_contacts.data!=''\n\t\tORDER BY user_auth.full_name ASC, plugin_thold_contacts.type ASC"); if (!empty($users)) { foreach ($users as $user) { $send_notification_array[$user['id']] = $user['full_name'] . ' - ' . ucfirst($user['type']); } } if (isset($thold_data['id'])) { $sql = 'SELECT contact_id as id FROM plugin_thold_threshold_contact WHERE thold_id=' . $thold_data['id']; $step = db_fetch_cell('SELECT rrd_step FROM data_template_data WHERE local_data_id = ' . $thold_data['local_data_id'], FALSE); } else { $sql = 'SELECT contact_id as id FROM plugin_thold_threshold_contact WHERE thold_id=0'; $step = db_fetch_cell('SELECT rrd_step FROM data_template_data WHERE local_data_id = ' . $thold_data['local_data_id'], FALSE); } include $config['base_path'] . '/plugins/thold/includes/arrays.php'; $data_fields = array(); $reference_types = get_reference_types($thold_data['local_data_id'], $step, $timearray); $temp = db_fetch_assoc('SELECT id, local_data_template_rrd_id, data_source_name, data_input_field_id FROM data_template_rrd WHERE local_data_id=' . $thold_data['local_data_id']); foreach ($temp as $d) { if ($d['data_input_field_id'] != 0) { $name = db_fetch_cell('SELECT name FROM data_input_fields WHERE id=' . $d['data_input_field_id']); } else { $name = $d['data_source_name']; } if ($d['id'] != $thold_data['data_template_rrd_id']) { $data_fields[$d['data_source_name']] = $name; } } $replacements = db_fetch_assoc_prepared('SELECT DISTINCT field_name FROM data_local AS dl INNER JOIN host_snmp_cache AS hsc ON dl.snmp_query_id=hsc.snmp_query_id AND dl.host_id=hsc.host_id WHERE dl.id = ?', array($thold_data['data_template_id'])); $nr = array(); if (sizeof($replacements)) { foreach ($replacements as $r) { $nr[] = "<span class='deviceUp'>|query_" . $r['field_name'] . "|</span>"; } } $vhf = explode('|', trim(VALID_HOST_FIELDS, '()')); if (sizeof($vhf)) { foreach ($vhf as $r) { $nr[] = "<span class='deviceUp'>|" . $r . "|</span>"; } } $replacements = "<br>" . __('Replacement Fields: %s', implode(", ", $nr)); $dss = db_fetch_assoc_prepared('SELECT data_source_name FROM data_template_rrd WHERE local_data_id = ?', array($thold_data['local_data_id'])); if (sizeof($dss)) { foreach ($dss as $ds) { $dsname[] = "<span class='deviceUp'>|ds:" . $ds["data_source_name"] . "|</span>"; } } $datasources = "<br>" . __('Data Sources: %s', implode(", ", $dsname)); $form_array = array('template_header' => array('friendly_name' => __('Template Settings'), 'method' => 'spacer'), 'template_enabled' => array('friendly_name' => __('Template Propagation Enabled'), 'method' => 'checkbox', 'default' => '', 'description' => __('Whether or not these settings will be propagates from the threshold template.'), 'value' => !empty($thold_data['template_enabled']) ? $thold_data['template_enabled'] : ''), 'template_name' => array('friendly_name' => __('Template Name'), 'method' => 'custom', 'default' => '', 'description' => __('Name of the Threshold Template the threshold was created from.'), 'value' => isset($thold_data['template_name']) ? $thold_data['template_name'] : 'N/A'), 'general_header' => array('friendly_name' => __('General Settings'), 'method' => 'spacer'), 'name' => array('friendly_name' => __('Threshold Name'), 'method' => 'textbox', 'max_length' => 100, 'size' => '70', 'default' => $desc . ' [' . $template_rrd['data_source_name'] . ']', 'description' => __('Provide the Thresholds a meaningful name'), 'value' => isset($thold_data['name']) ? $thold_data['name'] : ''), 'thold_enabled' => array('friendly_name' => __('Threshold Enabled'), 'method' => 'checkbox', 'default' => 'on', 'description' => __('Whether or not this threshold will be checked and alerted upon.'), 'value' => isset($thold_data['thold_enabled']) ? $thold_data['thold_enabled'] : ''), 'exempt' => array('friendly_name' => __('Weekend Exemption'), 'description' => __('If this is checked, this Threshold will not alert on weekends.'), 'method' => 'checkbox', 'default' => '', 'value' => isset($thold_data['exempt']) ? $thold_data['exempt'] : ''), 'restored_alert' => array('friendly_name' => __('Disable Restoration Email'), 'description' => __('If this is checked, Thold will not send an alert when the threshold has returned to normal status.'), 'method' => 'checkbox', 'default' => '', 'value' => isset($thold_data['restored_alert']) ? $thold_data['restored_alert'] : ''), 'thold_type' => array('friendly_name' => __('Threshold Type'), 'method' => 'drop_array', 'on_change' => 'changeTholdType()', 'array' => $thold_types, 'default' => read_config_option('thold_type'), 'description' => __('The type of Threshold that will be monitored.'), 'value' => isset($thold_data['thold_type']) ? $thold_data['thold_type'] : ''), 'repeat_alert' => array('friendly_name' => __('Re-Alert Cycle'), 'method' => 'drop_array', 'array' => $repeatarray, 'default' => read_config_option('alert_repeat'), 'description' => __('Repeat alert after this amount of time has pasted since the last alert.'), 'value' => isset($thold_data['repeat_alert']) ? $thold_data['repeat_alert'] : ''), 'thold_warning_header' => array('friendly_name' => __('Warning - High / Low Settings'), 'method' => 'spacer'), 'thold_warning_hi' => array('friendly_name' => __('High Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes above this number, warning will be triggered'), 'value' => isset($thold_data['thold_warning_hi']) ? $thold_data['thold_warning_hi'] : ''), 'thold_warning_low' => array('friendly_name' => __('Low Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes below this number, warning will be triggered'), 'value' => isset($thold_data['thold_warning_low']) ? $thold_data['thold_warning_low'] : ''), 'thold_warning_fail_trigger' => array('friendly_name' => __('Breach Duration'), 'method' => 'drop_array', 'array' => $alertarray, 'description' => __('The amount of time the data source must be in breach of the threshold for a warning to be raised.'), 'value' => isset($thold_data['thold_warning_fail_trigger']) ? $thold_data['thold_warning_fail_trigger'] : read_config_option('alert_trigger')), 'thold_header' => array('friendly_name' => __('Alert - High / Low Settings'), 'method' => 'spacer'), 'thold_hi' => array('friendly_name' => __('High Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes above this number, alert will be triggered'), 'value' => isset($thold_data['thold_hi']) ? $thold_data['thold_hi'] : ''), 'thold_low' => array('friendly_name' => __('Low Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes below this number, alert will be triggered'), 'value' => isset($thold_data['thold_low']) ? $thold_data['thold_low'] : ''), 'thold_fail_trigger' => array('friendly_name' => __('Breach Duration'), 'method' => 'drop_array', 'array' => $alertarray, 'description' => __('The amount of time the data source must be in breach of the threshold for an alert to be raised.'), 'value' => isset($thold_data['thold_fail_trigger']) ? $thold_data['thold_fail_trigger'] : read_config_option('alert_trigger')), 'time_warning_header' => array('friendly_name' => __('Warning - Time Based Settings'), 'method' => 'spacer'), 'time_warning_hi' => array('friendly_name' => __('High Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes above this number, warning will be triggered'), 'value' => isset($thold_data['time_warning_hi']) ? $thold_data['time_warning_hi'] : ''), 'time_warning_low' => array('friendly_name' => __('Low Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes below this number, warning will be triggered'), 'value' => isset($thold_data['time_warning_low']) ? $thold_data['time_warning_low'] : ''), 'time_warning_fail_trigger' => array('friendly_name' => __('Breach Count'), 'method' => 'textbox', 'max_length' => 5, 'size' => 10, 'description' => __('The number of times the data source must be in breach of the threshold.'), 'value' => isset($thold_data['time_warning_fail_trigger']) ? $thold_data['time_warning_fail_trigger'] : read_config_option('thold_warning_time_fail_trigger')), 'time_warning_fail_length' => array('friendly_name' => __('Breach Window'), 'method' => 'drop_array', 'array' => $timearray, 'description' => __('The amount of time in the past to check for threshold breaches.'), 'value' => isset($thold_data['time_warning_fail_length']) ? $thold_data['time_warning_fail_length'] : (read_config_option('thold_warning_time_fail_length') > 0 ? read_config_option('thold_warning_time_fail_length') : 1)), 'time_header' => array('friendly_name' => __('Alert - Time Based Settings'), 'method' => 'spacer'), 'time_hi' => array('friendly_name' => __('High Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes above this number, alert will be triggered'), 'value' => isset($thold_data['time_hi']) ? $thold_data['time_hi'] : ''), 'time_low' => array('friendly_name' => __('Low Threshold'), 'method' => 'textbox', 'max_length' => 100, 'size' => 10, 'description' => __('If set and data source value goes below this number, alert will be triggered'), 'value' => isset($thold_data['time_low']) ? $thold_data['time_low'] : ''), 'time_fail_trigger' => array('friendly_name' => __('Breach Count'), 'method' => 'textbox', 'max_length' => 5, 'size' => 10, 'default' => read_config_option('thold_time_fail_trigger'), 'description' => __('The number of times the data source must be in breach of the threshold.'), 'value' => isset($thold_data['time_fail_trigger']) ? $thold_data['time_fail_trigger'] : read_config_option('thold_time_fail_trigger')), 'time_fail_length' => array('friendly_name' => __('Breach Window'), 'method' => 'drop_array', 'array' => $timearray, 'description' => __('The amount of time in the past to check for threshold breaches.'), 'value' => isset($thold_data['time_fail_length']) ? $thold_data['time_fail_length'] : (read_config_option('thold_time_fail_length') > 0 ? read_config_option('thold_time_fail_length') : 1)), 'baseline_header' => array('friendly_name' => __('Baseline Settings'), 'method' => 'spacer'), 'bl_ref_time_range' => array('friendly_name' => __('Time range'), 'method' => 'drop_array', 'array' => $reference_types, 'description' => __('Specifies the point in the past (based on rrd resolution) that will be used as a reference'), 'value' => isset($thold_data['bl_ref_time_range']) ? $thold_data['bl_ref_time_range'] : read_config_option('alert_bl_timerange_def')), 'bl_pct_up' => array('friendly_name' => __('Deviation UP'), 'method' => 'textbox', 'max_length' => 3, 'size' => 10, 'description' => __('Specifies allowed deviation in percentage for the upper bound threshold. If not set, upper bound threshold will not be checked at all.'), 'value' => isset($thold_data['bl_pct_up']) ? $thold_data['bl_pct_up'] : ''), 'bl_pct_down' => array('friendly_name' => __('Deviation DOWN'), 'method' => 'textbox', 'max_length' => 3, 'size' => 10, 'description' => __('Specifies allowed deviation in percentage for the lower bound threshold. If not set, lower bound threshold will not be checked at all.'), 'value' => isset($thold_data['bl_pct_down']) ? $thold_data['bl_pct_down'] : ''), 'bl_fail_trigger' => array('friendly_name' => __('Baseline Trigger Count'), 'method' => 'textbox', 'max_length' => 3, 'size' => 10, 'description' => __('Number of consecutive times the data source must be in breach of the baseline threshold for an alert to be raised.<br>Leave empty to use default value (<b>Default: %s cycles</b>)', read_config_option('alert_bl_trigger')), 'value' => isset($thold_data['bl_fail_trigger']) ? $thold_data['bl_fail_trigger'] : read_config_option("alert_bl_trigger")), 'data_manipulation' => array('friendly_name' => __('Data Manipulation'), 'method' => 'spacer'), 'data_type' => array('friendly_name' => __('Data Type'), 'method' => 'drop_array', 'on_change' => 'changeDataType()', 'array' => $data_types, 'default' => read_config_option('data_type'), 'description' => __('Special formatting for the given data.'), 'value' => isset($thold_data['data_type']) ? $thold_data['data_type'] : ''), 'cdef' => array('friendly_name' => __('Threshold CDEF'), 'method' => 'drop_array', 'default' => 'NULL', 'description' => __('Apply this CDEF before returning the data.'), 'value' => isset($thold_data['cdef']) ? $thold_data['cdef'] : 0, 'array' => thold_cdef_select_usable_names()), 'percent_ds' => array('friendly_name' => __('Percent Datasource'), 'method' => 'drop_array', 'default' => 'NULL', 'description' => __('Second Datasource Item to use as total value to calculate percentage from.'), 'value' => isset($thold_data['percent_ds']) ? $thold_data['percent_ds'] : 0, 'array' => $data_fields), 'expression' => array('friendly_name' => __('RPN Expression'), 'method' => 'textarea', 'textarea_rows' => 3, 'textarea_cols' => 80, 'default' => '', 'description' => __('An RPN Expression is an RRDtool Compatible RPN Expression. Syntax includes all functions below in addition to both Device and Data Query replacement expressions such as <span class="deviceUp">|query_ifSpeed|</span>. To use a Data Source in the RPN Expression, you must use the syntax: <span class="deviceUp">|ds:dsname|</span>. For example, <span class="deviceUp">|ds:traffic_in|</span> will get the current value of the traffic_in Data Source for the RRDfile(s) associated with the Graph. Any Data Source for a Graph can be included.<br><br>Math Operators: <span class="deviceUp">+, -, /, *, %, ^</span><br>Functions: <span class="deviceUp">SIN, COS, TAN, ATAN, SQRT, FLOOR, CEIL, DEG2RAD, RAD2DEG, ABS, EXP, LOG, ATAN, ADNAN</span><br>Flow Operators: <span class="deviceUp">UN, ISINF, IF, LT, LE, GT, GE, EQ, NE</span><br>Comparison Functions: <span class="deviceUp">MAX, MIN, INF, NEGINF, NAN, UNKN, COUNT, PREV</span>%s %s', $replacements, $datasources), 'value' => isset($thold_data['expression']) ? $thold_data['expression'] : '', 'max_length' => '255', 'size' => '80'), 'other_header' => array('friendly_name' => __('Other Settings'), 'method' => 'spacer'), 'notify_warning' => array('friendly_name' => __('Warning Notification List'), 'method' => 'drop_sql', 'description' => __('You may specify choose a Notification List to receive Warnings for this Data Source'), 'value' => isset($thold_data['notify_warning']) ? $thold_data['notify_warning'] : '', 'none_value' => __('None'), 'sql' => 'SELECT id, name FROM plugin_notification_lists ORDER BY name'), 'notify_alert' => array('friendly_name' => __('Alert Notification List'), 'method' => 'drop_sql', 'description' => __('You may specify choose a Notification List to receive Alerts for this Data Source'), 'value' => isset($thold_data['notify_alert']) ? $thold_data['notify_alert'] : '', 'none_value' => __('None'), 'sql' => 'SELECT id, name FROM plugin_notification_lists ORDER BY name')); if (read_config_option("thold_alert_snmp") == 'on') { $extra = array('snmp_event_category' => array('friendly_name' => __('SNMP Notification - Event Category'), 'method' => 'textbox', 'description' => __('To allow a NMS to categorize different SNMP notifications more easily please fill in the category SNMP notifications for this template should make use of. E.g.: "disk_usage", "link_utilization", "ping_test", "nokia_firewall_cpu_utilization" ...'), 'value' => isset($thold_data['snmp_event_category']) ? $thold_data['snmp_event_category'] : '', 'default' => '', 'max_length' => '255'), 'snmp_event_severity' => array('friendly_name' => __('SNMP Notification - Alert Event Severity'), 'method' => 'drop_array', 'default' => '3', 'description' => __('Severity to be used for alerts. (low impact -> critical impact)'), 'value' => isset($thold_data['snmp_event_severity']) ? $thold_data['snmp_event_severity'] : 3, 'array' => array(1 => __('Low'), 2 => __('Medium'), 3 => __('High'), 4 => __('Critical')))); $form_array += $extra; if (read_config_option('thold_alert_snmp_warning') != 'on') { $extra = array('snmp_event_warning_severity' => array('friendly_name' => __('SNMP Notification - Warning Event Severity'), 'method' => 'drop_array', 'default' => '2', 'description' => __('Severity to be used for warnings. (Low impact -> Critical impact).<br>Note: The severity of warnings has to be equal or lower than the severity being defined for alerts.'), 'value' => isset($thold_data['snmp_event_warning_severity']) ? $thold_data['snmp_event_warning_severity'] : 2, 'array' => array(1 => __('Low'), 2 => __('Medium'), 3 => __('High'), 4 => __('Critical')))); } $form_array += $extra; } if (read_config_option('thold_disable_legacy') != 'on') { $extra = array('notify_accounts' => array('friendly_name' => __('Notify accounts'), 'method' => 'drop_multi', 'description' => __('This is a listing of accounts that will be notified when this threshold is breached.<br><br><br><br>'), 'array' => $send_notification_array, 'sql' => $sql), 'notify_extra' => array('friendly_name' => __('Alert Emails'), 'method' => 'textarea', 'textarea_rows' => 3, 'textarea_cols' => 50, 'description' => __('You may specify here extra Emails to receive alerts for this data source (comma separated)'), 'value' => isset($thold_data['notify_extra']) ? $thold_data['notify_extra'] : ''), 'notify_warning_extra' => array('friendly_name' => __('Warning Emails'), 'method' => 'textarea', 'textarea_rows' => 3, 'textarea_cols' => 50, 'description' => __('You may specify here extra Emails to receive warnings for this data source (comma separated)'), 'value' => isset($thold_data['notify_warning_extra']) ? $thold_data['notify_warning_extra'] : '')); $form_array += $extra; } else { $extra = array('notify_accounts' => array('method' => 'hidden', 'value' => 'ignore'), 'notify_extra' => array('method' => 'hidden', 'value' => isset($thold_data['notify_extra']) ? $thold_data['notify_extra'] : ''), 'notify_warning_extra' => array('method' => 'hidden', 'value' => isset($thold_data['notify_warning_extra']) ? $thold_data['notify_warning_extra'] : '')); $form_array += $extra; } draw_edit_form(array('config' => array('no_form_tag' => true), 'fields' => $form_array + array('id' => array('method' => 'hidden', 'value' => !empty($thold_data['id']) ? $thold_data['id'] : '0'), 'data_template_rrd_id' => array('method' => 'hidden', 'value' => isset($template_rrd) ? $template_rrd['id'] : '0'), 'host_id' => array('method' => 'hidden', 'value' => $thold_data['host_id']), 'local_data_id' => array('method' => 'hidden', 'value' => $thold_data['local_data_id'])))); html_end_box(); if (isset($_SESSION['data_return'])) { $ajax = false; } else { $ajax = true; } form_save_button('thold.php' . (!empty($thold_data['id']) ? '?id=' . $thold_data['id'] : ''), 'return', 'id', $ajax); ?> <script type='text/javascript'> function templateEnableDisable() { var status = $('#template_enabled').is(':checked'); $('#name').prop('disabled', status); $('#thold_type').prop('disabled', status); $('#thold_hi').prop('disabled', status); $('#thold_low').prop('disabled', status); $('#thold_fail_trigger').prop('disabled', status); $('#thold_warning_hi').prop('disabled', status); $('#thold_warning_low').prop('disabled', status); $('#thold_warning_fail_trigger').prop('disabled', status); $('#repeat_alert').prop('disabled', status); $('#notify_extra').prop('disabled', status); $('#notify_warning_extra').prop('disabled', status); $('#notify_warning').prop('disabled', status); $('#notify_alert').prop('disabled', status); $('#cdef').prop('disabled', status); $('#thold_enabled').prop('disabled', status); if ($('#notify_accounts')) $('#notify_accounts').prop('disabled', status); $('#time_hi').prop('disabled', status); $('#time_low').prop('disabled', status); $('#time_fail_trigger').prop('disabled', status); $('#time_fail_length').prop('disabled', status); $('#time_warning_hi').prop('disabled', status); $('#time_warning_low').prop('disabled', status); $('#time_warning_fail_trigger').prop('disabled', status); $('#time_warning_fail_length').prop('disabled', status); $('#data_type').prop('disabled', status); $('#percent_ds').prop('disabled', status); $('#expression').prop('disabled', status); $('#exempt').prop('disabled', status); $('#restored_alert').prop('disabled', status); if ($('#snmp_event_category')) $('#snmp_event_category').prop('disabled', status); if ($('#snmp_event_severity')) $('#snmp_event_severity').prop('disabled', status); if ($('#snmp_event_warning_severity')) $('#snmp_event_warning_severity').prop('disabled', status); } function changeTholdType() { switch($('#thold_type').val()) { case '0': thold_toggle_hilow(''); thold_toggle_baseline('none'); thold_toggle_time('none'); break; case '1': thold_toggle_hilow('none'); thold_toggle_baseline(''); thold_toggle_time('none'); break; case '2': thold_toggle_hilow('none'); thold_toggle_baseline('none'); thold_toggle_time(''); break; } } function changeDataType () { switch($('#data_type').val()) { case '0': $('#row_cdef').hide(); $('#row_percent_ds').hide(); $('#row_expression').hide(); break; case '1': $('#row_cdef').show(); $('#row_percent_ds').hide(); $('#row_expression').hide(); break; case '2': $('#row_cdef').hide() $('#row_percent_ds').show(); $('#row_expression').hide(); break; case '3': $('#row_expression').show(); $('#row_cdef').hide(); $('#row_percent_ds').hide(); break; } } function thold_toggle_hilow (status) { if (status == '') { $('#row_thold_header, #row_thold_hi, #row_thold_low, #row_thold_fail_trigger').show(); $('#row_thold_warning_header, #row_thold_warning_hi').show(); $('#row_thold_warning_low, #row_thold_warning_fail_trigger').show(); }else{ $('#row_thold_header, #row_thold_hi, #row_thold_low, #row_thold_fail_trigger').hide(); $('#row_thold_warning_header, #row_thold_warning_hi').hide(); $('#row_thold_warning_low, #row_thold_warning_fail_trigger').hide(); } } function thold_toggle_baseline(status) { if (status == '') { $('#row_baseline_header, #row_bl_ref_time_range').show(); $('#row_bl_pct_up, #row_bl_pct_down, #row_bl_fail_trigger').show(); }else{ $('#row_baseline_header, #row_bl_ref_time_range').hide(); $('#row_bl_pct_up, #row_bl_pct_down, #row_bl_fail_trigger').hide(); } } function thold_toggle_time(status) { if (status == '') { $('#row_time_header, #row_time_hi, #row_time_low, #row_time_fail_trigger, #row_time_fail_length').show(); $('#row_time_warning_header, #row_time_warning_hi, #row_time_warning_low').show(); $('#row_time_warning_fail_trigger, #row_time_warning_fail_length').show(); }else{ $('#row_time_header, #row_time_hi, #row_time_low, #row_time_fail_trigger, #row_time_fail_length').hide(); $('#row_time_warning_header, #row_time_warning_hi, #row_time_warning_low').hide(); $('#row_time_warning_fail_trigger, #row_time_warning_fail_length').hide(); } } function graphImage() { var id = $('#element').val(); $('#graphimage').attr(src, '../../graph_image.php?local_graph_id=' + id + '&rra_id=0&graph_start=-32400&graph_height=100&graph_width=300&graph_nolegend=true').change(); } $(function() { if ('<?php print $thold_data['thold_template_id']; ?> ' == '0') { $('#template_enabled').prop('disabled', true); } if ($('#notify_accounts option').length == 0) { $('#row_notify_accounts').hide(); } if ($('#notify_warning option').length == 0) { $('#row_notify_warning').hide(); } if ($('#notify_alert option').length == 0) { $('#row_notify_alert').hide(); } $('#notify_accounts').multiselect({ minWidth: '400', noneSelectedText: '<?php print __('Select Users(s)'); ?> ', selectedText: function(numChecked, numTotal, checkedItems) { myReturn = numChecked + ' <?php print __('Users Selected'); ?> '; $.each(checkedItems, function(index, value) { if (value.value == '0') { myReturn='<?php print __('All Users Selected'); ?> '; return false; } }); return myReturn; }, checkAllText: 'All', uncheckAllText: 'None', uncheckall: function() { $(this).multiselect('widget').find(':checkbox:first').each(function() { $(this).prop('checked', true); }); }, open: function() { size = $('#notify_accounts option').length * 18 + 20; if (size > 100) { size = 100; } $('ul.ui-multiselect-checkboxes').css('height', size + 'px'); }, click: function(event, ui) { checked=$(this).multiselect('widget').find('input:checked').length; if (ui.value == '0') { if (ui.checked == true) { $('#host').multiselect('uncheckAll'); $(this).multiselect('widget').find(':checkbox:first').each(function() { $(this).prop('checked', true); }); } }else if (checked == 0) { $(this).multiselect('widget').find(':checkbox:first').each(function() { $(this).click(); }); }else if ($(this).multiselect('widget').find('input:checked:first').val() == '0') { if (checked > 0) { $(this).multiselect('widget').find(':checkbox:first').each(function() { $(this).click(); $(this).prop('disable', true); }); } } } }).multiselectfilter( { label: 'Search', width: '150' }); templateEnableDisable(); $('#template_enabled').click(function() { templateEnableDisable(); }); <?php if (!isset($thold_data['thold_template_id']) || $thold_data['thold_template_id'] == '') { ?> $('#templated_enabled').prop('disabled', true); <?php } ?> changeTholdType (); changeDataType (); $('#element').change(function() { graphImage; }); }); </script> <?php }
function thold_build_cdef($id, $value, $rra, $ds) { $oldvalue = $value; $cdefs = db_fetch_assoc("select * from cdef_items where cdef_id = {$id} order by sequence"); if (sizeof($cdefs)) { foreach ($cdefs as $cdef) { if ($cdef['type'] == 4) { $cdef['type'] = 6; switch ($cdef['value']) { case 'CURRENT_DATA_SOURCE': $cdef['value'] = $oldvalue; // get_current_value($rra, $ds, 0); break; case 'CURRENT_GRAPH_MAXIMUM_VALUE': $cdef['value'] = get_current_value($rra, 'upper_limit', 0); break; case 'CURRENT_GRAPH_MINIMUM_VALUE': $cdef['value'] = get_current_value($rra, 'lower_limit', 0); break; case 'CURRENT_DS_MINIMUM_VALUE': $cdef['value'] = get_current_value($rra, 'rrd_minimum', 0); break; case 'CURRENT_DS_MAXIMUM_VALUE': $cdef['value'] = get_current_value($rra, 'rrd_maximum', 0); break; case 'VALUE_OF_HDD_TOTAL': $cdef['value'] = get_current_value($rra, 'hdd_total', 0); break; case 'ALL_DATA_SOURCES_NODUPS': // you can't have DUPs in a single data source, really... // you can't have DUPs in a single data source, really... case 'ALL_DATA_SOURCES_DUPS': $cdef['value'] = 0; $all_dsns = array(); $all_dsns = db_fetch_assoc("SELECT data_source_name FROM data_template_rrd WHERE local_data_id = {$rra}"); if (is_array($all_dsns)) { foreach ($all_dsns as $dsn) { $cdef['value'] += get_current_value($rra, $dsn['data_source_name'], 0); } } break; default: print 'CDEF property not implemented yet: ' . $cdef['value']; return $oldvalue; break; } } elseif ($cdef['type'] == 6) { $regresult = preg_match('/^\\|query_(.*)\\|$/', $cdef['value'], $matches); if ($regresult > 0) { // Grab result for query $cdef['value'] = db_fetch_cell("SELECT `h`.`field_value`\r\n\t\t\t\t\tFROM `poller_item` p, `host_snmp_cache` h\r\n\t\t\t\t\tWHERE `p`.`local_data_id` = '" . $rra . "'\r\n\t\t\t\t\tAND `p`.`host_id` = `h`.`host_id`\r\n\t\t\t\t\tAND `h`.`field_name` = '" . $matches[1] . "'\r\n\t\t\t\t\tAND `p`.`rrd_name` = 'traffic_in'\r\n\t\t\t\t\tAND SUBSTRING_INDEX(`p`.`arg1`, '.', -1 ) = `h`.`snmp_index`", FALSE); } } $cdef_array[] = $cdef; } } $x = count($cdef_array); if ($x == 0) { return $oldvalue; } $stack = array(); // operation stack for RPN array_push($stack, $cdef_array[0]); // first one always goes on $cursor = 1; // current pointer through RPN operations list while ($cursor < $x) { $type = $cdef_array[$cursor]['type']; switch ($type) { case 6: array_push($stack, $cdef_array[$cursor]); break; case 2: // this is a binary operation. pop two values, and then use them. $v1 = thold_expression_rpn_pop($stack); $v2 = thold_expression_rpn_pop($stack); $result = thold_rpn($v2['value'], $v1['value'], $cdef_array[$cursor]['value']); // put the result back on the stack. array_push($stack, array('type' => 6, 'value' => $result)); break; default: print 'Unknown RPN type: '; print $cdef_array[$cursor]['type']; return $oldvalue; break; } $cursor++; } return $stack[0]['value']; }
if ($found) { break; } } if (!$found) { continue; } $xml .= "<staticanalysis>"; $xml .= add_XML_value("group_name", $static_group["name"]); $xml .= add_XML_value("group_name_clean", sanitize_string($static_group["name"])); foreach ($static_measurements as $measurement) { $xml .= "<measurement>"; $xml .= add_XML_value("name", $measurement); $xml .= add_XML_value("nice_name", sanitize_string($measurement)); $xml .= add_XML_value("sort", $sort["build_" . $measurement]); $value = get_current_value($static_group["name"], $measurement); $xml .= add_XML_value("value", $value); $chart_data = get_chart_data($static_group["name"], $measurement); $xml .= add_XML_value("chart", $chart_data); $xml .= "</measurement>"; } $xml .= "</staticanalysis>"; } $end = microtime_float(); $xml .= "<generationtime>" . round($end - $start, 3) . "</generationtime>"; $xml .= "</cdash>"; // Now do the xslt transition if (!isset($NoXSLGenerate)) { generate_XSLT($xml, "overview"); } // Replace various characters that trip up Javascript with underscores.
<h2>Mapping</h2> </section> <section class="item"> <?php echo form_open_multipart(uri_string()); echo '<a onClick="window.open(\'/admin/streams_import/profiles/raw_data/' . $this->uri->segment(5) . '\', \'NOM\', \'scrollbars=yes,width=550,height=600\')"target=\'_blank\'>See the raw data</a>'; ?> <table> <tr> <td>Source</td> <td>Destination</td> </tr> <?php $i = 0; foreach ($fields as $key => $value) { echo "<tr><td>" . form_dropdown("source[{$i}]", $csv_dropdown, get_current_value($this->uri->segment(5), $key, $mode = 2)) . "</td><td>" . form_dropdown("destination[{$i}]", $fields, get_current_value($this->uri->segment(5), $key, $mode = 1)) . "</td></tr>"; $i++; } ?> </table> <?php echo form_hidden('profileID', $this->uri->segment(5)); echo form_hidden('counter', $i); ?> <div class="float-right buttons"> <button type="submit" name="btnAction" value="save" class="btn blue"> <span><?php echo lang('buttons.save'); ?>
function thold_build_cdef(&$cdefs, $value, $rra, $ds) { $oldvalue = $value; if (sizeof($cdefs)) { foreach ($cdefs as $cdef) { if ($cdef['type'] == 4) { $cdef['type'] = 6; switch ($cdef['value']) { case 'CURRENT_DATA_SOURCE': $cdef['value'] = $oldvalue; // get_current_value($rra, $ds, 0); break; case 'CURRENT_GRAPH_MAXIMUM_VALUE': $cdef['value'] = get_current_value($rra, 'upper_limit', 0); break; case 'CURRENT_GRAPH_MINIMUM_VALUE': $cdef['value'] = get_current_value($rra, 'lower_limit', 0); break; case 'CURRENT_DS_MINIMUM_VALUE': $cdef['value'] = get_current_value($rra, 'rrd_minimum', 0); break; case 'CURRENT_DS_MAXIMUM_VALUE': $cdef['value'] = get_current_value($rra, 'rrd_maximum', 0); break; case 'VALUE_OF_HDD_TOTAL': $cdef['value'] = get_current_value($rra, 'hdd_total', 0); break; case 'ALL_DATA_SOURCES_NODUPS': // you can't have DUPs in a single data source, really... // you can't have DUPs in a single data source, really... case 'ALL_DATA_SOURCES_DUPS': $cdef['value'] = 0; $all_dsns = array(); $all_dsns = db_fetch_assoc("SELECT data_source_name FROM data_template_rrd WHERE local_data_id = {$rra}"); if (is_array($all_dsns)) { foreach ($all_dsns as $dsn) { $cdef['value'] += get_current_value($rra, $dsn['data_source_name'], 0); } } break; default: print 'CDEF property not implemented yet: ' . $cdef['value']; return $oldvalue; break; } } elseif ($cdef['type'] == 6) { $regresult = preg_match('/^\\|query_([A-Za-z0-9_]+)\\|$/', $cdef['value'], $matches); if ($regresult > 0) { $sql_query = "SELECT host_snmp_cache.field_value\n\t\t\t\t\tFROM data_local \n\t\t\t\t\tINNER JOIN host_snmp_cache \n\t\t\t\t\tON host_snmp_cache.host_id = data_local.host_id\n\t\t\t\t\tAND host_snmp_cache.snmp_query_id = data_local.snmp_query_id\n\t\t\t\t\tAND host_snmp_cache.snmp_index = data_local.snmp_index\n\t\t\t\t\tWHERE data_local.id = {$rra} AND host_snmp_cache.field_name = '" . $matches[1] . "'"; $cdef['value'] = db_fetch_cell($sql_query); } } $cdef_array[] = $cdef; } } $x = count($cdef_array); if ($x == 0) { return $oldvalue; } $stack = array(); // operation stack for RPN array_push($stack, $cdef_array[0]); // first one always goes on $cursor = 1; // current pointer through RPN operations list while ($cursor < $x) { $type = $cdef_array[$cursor]['type']; switch ($type) { case 6: array_push($stack, $cdef_array[$cursor]); break; case 2: // this is a binary operation. pop two values, and then use them. $v1 = thold_expression_rpn_pop($stack); $v2 = thold_expression_rpn_pop($stack); $result = thold_rpn($v2['value'], $v1['value'], $cdef_array[$cursor]['value']); // put the result back on the stack. array_push($stack, array('type' => 6, 'value' => $result)); break; default: print 'Unknown RPN type: '; print $cdef_array[$cursor]['type']; return $oldvalue; break; } $cursor++; } return $stack[0]['value']; }