Beispiel #1
0
function ping_host()
{
    input_validate_input_number($_REQUEST['id']);
    if (empty($_REQUEST['id'])) {
        return "";
    }
    $host = db_fetch_row_prepared('SELECT * FROM host WHERE id = ?', array($_REQUEST['id']));
    $am = $host['availability_method'];
    $anym = false;
    if ($am == AVAIL_SNMP || $am == AVAIL_SNMP_GET_NEXT || $am == AVAIL_SNMP_GET_SYSDESC || $am == AVAIL_SNMP_AND_PING || $am == AVAIL_SNMP_OR_PING) {
        $anym = true;
        print "SNMP Information<br>\n";
        print "<span style='font-size: 10px; font-weight: normal; font-family: monospace;'>\n";
        if ($host['snmp_community'] == '' && $host['snmp_username'] == '' || $host['snmp_version'] == 0) {
            print "<span style='color: #ab3f1e; font-weight: bold;'>SNMP not in use</span>\n";
        } else {
            $snmp_system = cacti_snmp_get($host['hostname'], $host['snmp_community'], '.1.3.6.1.2.1.1.1.0', $host['snmp_version'], $host['snmp_username'], $host['snmp_password'], $host['snmp_auth_protocol'], $host['snmp_priv_passphrase'], $host['snmp_priv_protocol'], $host['snmp_context'], $host['snmp_port'], $host['snmp_timeout'], read_config_option('snmp_retries'), SNMP_WEBUI);
            /* modify for some system descriptions */
            /* 0000937: System output in host.php poor for Alcatel */
            if (substr_count($snmp_system, '00:')) {
                $snmp_system = str_replace('00:', '', $snmp_system);
                $snmp_system = str_replace(':', ' ', $snmp_system);
            }
            if ($snmp_system == '') {
                print "<span class='hostDown'>SNMP error</span>\n";
            } else {
                $snmp_uptime = cacti_snmp_get($host['hostname'], $host['snmp_community'], '.1.3.6.1.2.1.1.3.0', $host['snmp_version'], $host['snmp_username'], $host['snmp_password'], $host['snmp_auth_protocol'], $host['snmp_priv_passphrase'], $host['snmp_priv_protocol'], $host['snmp_context'], $host['snmp_port'], $host['snmp_timeout'], read_config_option('snmp_retries'), SNMP_WEBUI);
                $snmp_hostname = cacti_snmp_get($host['hostname'], $host['snmp_community'], '.1.3.6.1.2.1.1.5.0', $host['snmp_version'], $host['snmp_username'], $host['snmp_password'], $host['snmp_auth_protocol'], $host['snmp_priv_passphrase'], $host['snmp_priv_protocol'], $host['snmp_context'], $host['snmp_port'], $host['snmp_timeout'], read_config_option('snmp_retries'), SNMP_WEBUI);
                $snmp_location = cacti_snmp_get($host['hostname'], $host['snmp_community'], '.1.3.6.1.2.1.1.6.0', $host['snmp_version'], $host['snmp_username'], $host['snmp_password'], $host['snmp_auth_protocol'], $host['snmp_priv_passphrase'], $host['snmp_priv_protocol'], $host['snmp_context'], $host['snmp_port'], $host['snmp_timeout'], read_config_option('snmp_retries'), SNMP_WEBUI);
                $snmp_contact = cacti_snmp_get($host['hostname'], $host['snmp_community'], '.1.3.6.1.2.1.1.4.0', $host['snmp_version'], $host['snmp_username'], $host['snmp_password'], $host['snmp_auth_protocol'], $host['snmp_priv_passphrase'], $host['snmp_priv_protocol'], $host['snmp_context'], $host['snmp_port'], $host['snmp_timeout'], read_config_option('snmp_retries'), SNMP_WEBUI);
                print '<strong>System:</strong>' . html_split_string($snmp_system) . "<br>\n";
                $days = intval($snmp_uptime / (60 * 60 * 24 * 100));
                $remainder = $snmp_uptime % (60 * 60 * 24 * 100);
                $hours = intval($remainder / (60 * 60 * 100));
                $remainder = $remainder % (60 * 60 * 100);
                $minutes = intval($remainder / (60 * 100));
                print "<strong>Uptime:</strong> {$snmp_uptime}";
                print "&nbsp;({$days} days, {$hours} hours, {$minutes} minutes)<br>\n";
                print "<strong>Hostname:</strong> {$snmp_hostname}<br>\n";
                print "<strong>Location:</strong> {$snmp_location}<br>\n";
                print "<strong>Contact:</strong> {$snmp_contact}<br>\n";
            }
        }
        print "</span>\n";
    }
    if ($am == AVAIL_PING || $am == AVAIL_SNMP_AND_PING || $am == AVAIL_SNMP_OR_PING) {
        $anym = true;
        /* create new ping socket for host pinging */
        $ping = new Net_Ping();
        $ping->host = $host;
        $ping->port = $host['ping_port'];
        /* perform the appropriate ping check of the host */
        $ping_results = $ping->ping(AVAIL_PING, $host['ping_method'], $host['ping_timeout'], $host['ping_retries']);
        if ($ping_results == true) {
            $host_down = false;
            $class = 'hostUp';
        } else {
            $host_down = true;
            $class = 'hostDown';
        }
        print "Ping Results<br>\n";
        print "<span class='" . $class . "'>" . $ping->ping_response . "</span>\n";
    }
    if ($anym == false) {
        print "No Ping or SNMP Availability Check In Use<br><br>\n";
    }
}
Beispiel #2
0
function thold_update_host_status () {
	global $config;
	// Return if we aren't set to notify
	$deadnotify = (read_config_option('alert_deadnotify') == 'on');
	if (!$deadnotify) return 0;
	include_once($config['base_path'] . '/plugins/thold/thold_functions.php');

	if (api_plugin_is_enabled('maint')) {
		include_once($config["base_path"] . '/plugins/maint/functions.php');
	}

	$alert_email = read_config_option('alert_email');
	$ping_failure_count = read_config_option('ping_failure_count');

	// Lets find hosts that were down, but are now back up
	$failed = db_fetch_assoc("SELECT * FROM plugin_thold_host_failed");
	if (sizeof($failed)) {
		foreach($failed as $fh) {
			if (!empty($fh['host_id'])) {
				if (api_plugin_is_enabled('maint')) {
					if (plugin_maint_check_cacti_host ($fh['host_id'])) {
						continue;
					}
				}
				$host = db_fetch_row('SELECT * FROM host WHERE id = ' . $fh['host_id']);
				if ($host['status'] == HOST_UP) {
					$snmp_system = '';
					$snmp_hostname = '';
					$snmp_location = '';
					$snmp_contact = '';
					$snmp_uptime = '';
					$uptimelong = '';
					$downtimemsg = '';

					if (($host["snmp_community"] == "" && $host["snmp_username"] == "") || $host["snmp_version"] == 0) {
						// SNMP not in use
						$snmp_system = 'SNMP not in use';
					} else {
						$snmp_system = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.1.0", $host["snmp_version"],
										$host["snmp_username"], $host["snmp_password"],
										$host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"],
										$host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);

						if (substr_count($snmp_system, "00:")) {
							$snmp_system = str_replace("00:", "", $snmp_system);
							$snmp_system = str_replace(":", " ", $snmp_system);
						}
						if ($snmp_system != "") {
							$snmp_uptime   = cacti_snmp_get($host['hostname'], $host['snmp_community'], ".1.3.6.1.2.1.1.3.0", $host['snmp_version'],
											$host['snmp_username'], $host['snmp_password'],
											$host['snmp_auth_protocol'], $host['snmp_priv_passphrase'], $host['snmp_priv_protocol'],
											$host['snmp_context'], $host['snmp_port'], $host['snmp_timeout'], read_config_option("snmp_retries"), SNMP_WEBUI);
							 $snmp_hostname = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.5.0", $host["snmp_version"],
											$host["snmp_username"], $host["snmp_password"],
											$host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"],
											$host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
							 $snmp_location = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.6.0", $host["snmp_version"],
											$host["snmp_username"], $host["snmp_password"],
											$host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"],
											$host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
							 $snmp_contact  = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.4.0", $host["snmp_version"],
											$host["snmp_username"], $host["snmp_password"],
											$host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"],
											$host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
							$days      = intval($snmp_uptime / (60*60*24*100));
							$remainder = $snmp_uptime % (60*60*24*100);
							$hours     = intval($remainder / (60*60*100));
							$remainder = $remainder % (60*60*100);
							$minutes   = intval($remainder / (60*100));
							$uptimelong = $days . "d " . $hours . "h " . $minutes . "m";
						}
						$downtime = time() - strtotime($host['status_fail_date']);
						$downtime_days = floor($downtime/86400);
						$downtime_hours = floor(($downtime - ($downtime_days * 86400))/3600);
						$downtime_minutes = floor(($downtime - ($downtime_days * 86400) - ($downtime_hours * 3600))/60);
						$downtime_seconds = $downtime - ($downtime_days * 86400) - ($downtime_hours * 3600) - ($downtime_minutes * 60);
						if ($downtime_days > 0 ) {
							$downtimemsg = $downtime_days . "d " . $downtime_hours . "h " . $downtime_minutes . "m " . $downtime_seconds . "s ";
						} elseif ($downtime_hours > 0 ) {
							$downtimemsg = $downtime_hours . "h " . $downtime_minutes . "m " . $downtime_seconds . "s";
						} elseif ($downtime_minutes > 0 ) {
							$downtimemsg = $downtime_minutes . "m " . $downtime_seconds . "s";
						} else {
							$downtimemsg = $downtime_seconds . "s ";
						}
					}


					$subject = read_config_option('thold_up_subject');
					if ($subject == '') {
						$subject = 'Host Notice: <DESCRIPTION> (<HOSTNAME>) returned from DOWN state';
					}
					$subject = str_replace('<HOSTNAME>', !$snmp_hostname ? $host['hostname'] : $snmp_hostname, $subject);
					$subject = str_replace('<DESCRIPTION>', $host['description'], $subject);
					$subject = str_replace('<DOWN/UP>', 'UP', $subject);
					$subject = strip_tags($subject);

					$msg = read_config_option('thold_up_text');
					if ($msg == '') {
						$msg = '<br>System <DESCRIPTION> (<HOSTNAME>) status: <DOWN/UP><br><br>Current ping response: <CUR_TIME> ms<br>Average system response : <AVG_TIME> ms<br>System availability: <AVAILABILITY><br>Total Checks Since Clear: <TOT_POLL><br>Total Failed Checks: <FAIL_POLL><br>Last Date Checked UP: <LAST_FAIL><br>Host Previously DOWN for: <DOWNTIME><br><br>Snmp Info:<br>Name - <SNMP_HOSTNAME><br>Location - <SNMP_LOCATION><br>Uptime - <UPTIMETEXT> (<UPTIME> ms)<br>System - <SNMP_SYSTEM><br><br>NOTE: <NOTES>';
					}
					$msg = str_replace('<SUBJECT>', $subject, $msg);
					$msg = str_replace('<HOSTNAME>', $host['hostname'], $msg);
					$msg = str_replace('<DESCRIPTION>', $host['description'], $msg);
					$msg = str_replace('<UPTIME>', $snmp_uptime, $msg);
					$msg = str_replace('<UPTIMETEXT>', $uptimelong, $msg);

					$msg = str_replace('<DOWNTIME>', $downtimemsg, $msg);
					$msg = str_replace('<MESSAGE>', '', $msg);
					$msg = str_replace('<DOWN/UP>', 'UP', $msg);

					$msg = str_replace('<SNMP_HOSTNAME>', $snmp_hostname, $msg);
					$msg = str_replace('<SNMP_LOCATION>', $snmp_location, $msg);
					$msg = str_replace('<SNMP_CONTACT>', $snmp_contact, $msg);
					$msg = str_replace('<SNMP_SYSTEM>', html_split_string($snmp_system), $msg);
					$msg = str_replace('<LAST_FAIL>', $host["status_fail_date"], $msg);
					$msg = str_replace('<AVAILABILITY>', round(($host["availability"]), 2) . ' %', $msg);
					$msg = str_replace('<TOT_POLL>', $host["total_polls"], $msg);
					$msg = str_replace('<FAIL_POLL>', $host["failed_polls"], $msg);
					$msg = str_replace('<CUR_TIME>', round(($host["cur_time"]), 2), $msg);
					$msg = str_replace('<AVG_TIME>', round(($host["avg_time"]), 2), $msg);
					$msg = str_replace('<NOTES>', $host["notes"], $msg);
					$msg = str_replace("\n", '<br>', $msg);
					switch($host['thold_send_email']) {
						case '0': // Disabled
							$alert_email = '';
							break;
						case '1': // Global List
							break;
						case '2': // Host List Only
							$alert_email = get_thold_notification_emails($host['thold_host_email']);
							break;
						case '3': // Global and Host List
							$alert_email = $alert_email . ',' . get_thold_notification_emails($host['thold_host_email']);
							break;
					}

					if ($alert_email == '' && $host['thold_send_email'] > 0) {
						cacti_log('THOLD: Can not send a Host Recovering Email since the \'Alert Email\' setting is not set !', true, 'POLLER');
					} elseif ($host['thold_send_email'] == '0') {
						cacti_log('THOLD: Did not send a Host Recovering Email, disabled per host setting : ' . $host['description'] . ' !', true, 'POLLER');
					} elseif ($alert_email != '') {
						thold_mail($alert_email, '', $subject, $msg, '');
					}
					thold_log(array(
						"type" => 3,
						"time" => time(),
						"host_id" => $host['id'],
						"graph_id" => 0,
						"threshold_id" => 0,
						"threshold_value" => 'Up/Down',
						"current" => 'Up',
						"status" => 5,
						"description" => 'Host Notice: '.$host['hostname'].' returned from DOWN state',
						"emails" => $alert_email
						)	
					);
				}
			}
		}
	}

	// Lets find hosts that are down
	$hosts = db_fetch_assoc('SELECT *
		FROM host
		WHERE disabled=""
		AND status=' . HOST_DOWN . '
		AND status_event_count=' . $ping_failure_count);

	$total_hosts = sizeof($hosts);
	if (count($hosts)) {
		foreach($hosts as $host) {
			if (api_plugin_is_enabled('maint')) {
				if (plugin_maint_check_cacti_host ($host['id'])) {
					continue;
				}
			}

			$downtime = time() - strtotime($host['status_rec_date']);
			$downtime_days = floor($downtime/86400);
			$downtime_hours = floor(($downtime - ($downtime_days * 86400))/3600);
			$downtime_minutes = floor(($downtime - ($downtime_days * 86400) - ($downtime_hours * 3600))/60);
			$downtime_seconds = $downtime - ($downtime_days * 86400) - ($downtime_hours * 3600) - ($downtime_minutes * 60);
			if ($downtime_days > 0 ) {
				$downtimemsg = $downtime_days . "d " . $downtime_hours . "h " . $downtime_minutes . "m " . $downtime_seconds . "s ";
			} elseif ($downtime_hours > 0 ) {
				$downtimemsg = $downtime_hours . "h " . $downtime_minutes . "m " . $downtime_seconds . "s";
			} elseif ($downtime_minutes > 0 ) {
				$downtimemsg = $downtime_minutes . "m " . $downtime_seconds . "s";
			} else {
				$downtimemsg = $downtime_seconds . "s ";
			}
			
			/*$subject = read_config_option('thold_down_subject');
			if ($subject == '') {
				$subject = 'Host Error: <DESCRIPTION> (<HOSTNAME>) is DOWN';
			}
			$subject = str_replace('<HOSTNAME>', $host['hostname'], $subject); */

			$subject = read_config_option('thold_down_subject');
			if ($subject == '') {
				$subject = 'Host Error: <DESCRIPTION> (<HOSTNAME>) is DOWN';
			}
			$snmpsys = db_fetch_assoc('SELECT snmp_sysName, snmp_sysLocation, snmp_sysDescr FROM mac_track_devices WHERE hostname = \''.$host['hostname'].'\'');
			$subject = str_replace('<HOSTNAME>', !$snmpsys ? $host['hostname'] : $snmpsys[0]['snmp_sysName'], $subject);
			$subject = str_replace('<DESCRIPTION>', $host['description'], $subject);
			$subject = str_replace('<DOWN/UP>', 'DOWN', $subject);
			$subject = strip_tags($subject);

			$msg = read_config_option('thold_down_text');
			if ($msg == '') {
				$msg = 'System Error : <DESCRIPTION> (<HOSTNAME>) is <DOWN/UP><br>Reason: <MESSAGE><SNMP_HOSTNAME><SNMP_LOCATION><SNMP_SYSTEM><br><br>Average system response : <AVG_TIME> ms<br>System availability: <AVAILABILITY><br>Total Checks Since Clear: <TOT_POLL><br>Total Failed Checks: <FAIL_POLL><br>Last Date Checked DOWN : <LAST_FAIL><br>Host Previously UP for: <DOWNTIME><br>NOTE: <NOTES>';
			}
			$msg = str_replace('<SUBJECT>', $subject, $msg);
			$msg = str_replace('<HOSTNAME>', $host['hostname'], $msg);
			$msg = str_replace('<DESCRIPTION>', $host['description'], $msg);
			$msg = str_replace('<UPTIME>', '', $msg);
			$msg = str_replace('<DOWNTIME>', $downtimemsg, $msg);
			$msg = str_replace('<MESSAGE>', $host['status_last_error'], $msg);
			$msg = str_replace('<DOWN/UP>', 'DOWN', $msg);
			$msg = str_replace('<SNMP_HOSTNAME>', !$snmpsys ? '' : '<br><br>Device name: '.$snmpsys[0]['snmp_sysName'], $msg);
			$msg = str_replace('<SNMP_LOCATION>', !$snmpsys ? '' : '<br>Location: '.$snmpsys[0]['snmp_sysLocation'], $msg);
			$msg = str_replace('<SNMP_CONTACT>', '', $msg);
			$msg = str_replace('<SNMP_SYSTEM>', !$snmpsys ? '' : '<br>Description: '.$snmpsys[0]['snmp_sysDescr'], $msg);
			$msg = str_replace('<LAST_FAIL>', $host["status_fail_date"], $msg);
			$msg = str_replace('<AVAILABILITY>', round(($host["availability"]), 2) . ' %', $msg);
			$msg = str_replace('<CUR_TIME>', round(($host["cur_time"]), 2), $msg);
			$msg = str_replace('<TOT_POLL>', $host["total_polls"], $msg);
			$msg = str_replace('<FAIL_POLL>', $host["failed_polls"], $msg);
			$msg = str_replace('<AVG_TIME>', round(($host["avg_time"]), 2), $msg);
			$msg = str_replace('<NOTES>', $host["notes"], $msg);
			$msg = str_replace("\n", '<br>', $msg);
			switch($host['thold_send_email']) {
				case '0': // Disabled
					$alert_email = '';
					break;
				case '1': // Global List
					break;
				case '2': // Host List Only
					$alert_email = get_thold_notification_emails($host['thold_host_email']);
					break;
				case '3': // Global and Host List
					$alert_email = $alert_email . ',' . get_thold_notification_emails($host['thold_host_email']);
					break;
			}

			if ($alert_email == '' && $host['thold_send_email'] > 0) {
				cacti_log('THOLD: Can not send a Host Down Email since the \'Alert Email\' setting is not set !', true, 'POLLER');
			} elseif ($host['thold_send_email'] == '0') {
				cacti_log('THOLD: Did not send a Host Down Email, disabled per host setting : ' . $host['description'] . ' !', true, 'POLLER');
			} elseif ($alert_email != '') {
				thold_mail($alert_email, '', $subject, $msg, '');
			}
			thold_log(array(
				"type" => 3,
				"time" => time(),
				"host_id" => $host['id'],
				"graph_id" => 0,
				"threshold_id" => 0,
				"threshold_value" => 'Up/Down',
				"current" => 'Down',
				"status" => 4,
				"description" => 'Host Error: '.$host['hostname'].' is DOWN',
				"emails" => $alert_email
				)	
			);
		}
	}

	// Now lets record all failed hosts
	db_execute("TRUNCATE TABLE plugin_thold_host_failed");
	$hosts = db_fetch_assoc('SELECT id
		FROM host
		WHERE disabled=""
		AND status!=' . HOST_UP);

	$failed = '';
	if (sizeof($hosts)) {
		foreach ($hosts as $host) {
			if (api_plugin_is_enabled('maint')) {
				if (plugin_maint_check_cacti_host ($host['id'])) {
					continue;
				}
			}
			$failed .= (strlen($failed) ? "), (":"(") . $host['id'];
		}
		$failed .= ")";

		db_execute("INSERT INTO plugin_thold_host_failed (host_id) VALUES $failed");
	}

	return $total_hosts;
}
Beispiel #3
0
function thold_update_host_status()
{
    global $config;
    // Return if we aren't set to notify
    $deadnotify = read_config_option('alert_deadnotify') == 'on';
    if (!$deadnotify) {
        return 0;
    }
    include_once $config['base_path'] . '/plugins/thold/thold_functions.php';
    if (api_plugin_is_enabled('maint')) {
        include_once $config['base_path'] . '/plugins/maint/functions.php';
    }
    $alert_email = read_config_option('alert_email');
    $ping_failure_count = read_config_option('ping_failure_count');
    // Lets find hosts that were down, but are now back up
    $failed = db_fetch_assoc('SELECT * FROM plugin_thold_host_failed');
    if (sizeof($failed)) {
        foreach ($failed as $fh) {
            if (!empty($fh['host_id'])) {
                if (api_plugin_is_enabled('maint')) {
                    if (plugin_maint_check_cacti_host($fh['host_id'])) {
                        continue;
                    }
                }
                $host = db_fetch_row('SELECT * FROM host WHERE id = ' . $fh['host_id']);
                if (isset($host['status']) && $host['status'] == HOST_UP) {
                    $snmp_system = '';
                    $snmp_hostname = '';
                    $snmp_location = '';
                    $snmp_contact = '';
                    $snmp_uptime = '';
                    $uptimelong = '';
                    $downtimemsg = '';
                    if ($host['snmp_community'] == '' && $host['snmp_username'] == '' || $host['snmp_version'] == 0) {
                        // SNMP not in use
                        $snmp_system = 'SNMP not in use';
                    } else {
                        $snmp_system = cacti_snmp_get($host['hostname'], $host['snmp_community'], '.1.3.6.1.2.1.1.1.0', $host['snmp_version'], $host['snmp_username'], $host['snmp_password'], $host['snmp_auth_protocol'], $host['snmp_priv_passphrase'], $host['snmp_priv_protocol'], $host['snmp_context'], $host['snmp_port'], $host['snmp_timeout'], read_config_option('snmp_retries'), SNMP_WEBUI);
                        if (substr_count($snmp_system, '00:')) {
                            $snmp_system = str_replace('00:', '', $snmp_system);
                            $snmp_system = str_replace(':', ' ', $snmp_system);
                        }
                        if ($snmp_system != '') {
                            $snmp_uptime = cacti_snmp_get($host['hostname'], $host['snmp_community'], '.1.3.6.1.2.1.1.3.0', $host['snmp_version'], $host['snmp_username'], $host['snmp_password'], $host['snmp_auth_protocol'], $host['snmp_priv_passphrase'], $host['snmp_priv_protocol'], $host['snmp_context'], $host['snmp_port'], $host['snmp_timeout'], read_config_option('snmp_retries'), SNMP_WEBUI);
                            $snmp_hostname = cacti_snmp_get($host['hostname'], $host['snmp_community'], '.1.3.6.1.2.1.1.5.0', $host['snmp_version'], $host['snmp_username'], $host['snmp_password'], $host['snmp_auth_protocol'], $host['snmp_priv_passphrase'], $host['snmp_priv_protocol'], $host['snmp_context'], $host['snmp_port'], $host['snmp_timeout'], read_config_option('snmp_retries'), SNMP_WEBUI);
                            $snmp_location = cacti_snmp_get($host['hostname'], $host['snmp_community'], '.1.3.6.1.2.1.1.6.0', $host['snmp_version'], $host['snmp_username'], $host['snmp_password'], $host['snmp_auth_protocol'], $host['snmp_priv_passphrase'], $host['snmp_priv_protocol'], $host['snmp_context'], $host['snmp_port'], $host['snmp_timeout'], read_config_option('snmp_retries'), SNMP_WEBUI);
                            $snmp_contact = cacti_snmp_get($host['hostname'], $host['snmp_community'], '.1.3.6.1.2.1.1.4.0', $host['snmp_version'], $host['snmp_username'], $host['snmp_password'], $host['snmp_auth_protocol'], $host['snmp_priv_passphrase'], $host['snmp_priv_protocol'], $host['snmp_context'], $host['snmp_port'], $host['snmp_timeout'], read_config_option('snmp_retries'), SNMP_WEBUI);
                            $days = intval($snmp_uptime / (60 * 60 * 24 * 100));
                            $remainder = $snmp_uptime % (60 * 60 * 24 * 100);
                            $hours = intval($remainder / (60 * 60 * 100));
                            $remainder = $remainder % (60 * 60 * 100);
                            $minutes = intval($remainder / (60 * 100));
                            $uptimelong = $days . 'd ' . $hours . 'h ' . $minutes . 'm';
                        }
                        $downtime = time() - strtotime($host['status_fail_date']);
                        $downtime_days = floor($downtime / 86400);
                        $downtime_hours = floor(($downtime - $downtime_days * 86400) / 3600);
                        $downtime_minutes = floor(($downtime - $downtime_days * 86400 - $downtime_hours * 3600) / 60);
                        $downtime_seconds = $downtime - $downtime_days * 86400 - $downtime_hours * 3600 - $downtime_minutes * 60;
                        if ($downtime_days > 0) {
                            $downtimemsg = $downtime_days . 'd ' . $downtime_hours . 'h ' . $downtime_minutes . 'm ' . $downtime_seconds . 's ';
                        } elseif ($downtime_hours > 0) {
                            $downtimemsg = $downtime_hours . 'h ' . $downtime_minutes . 'm ' . $downtime_seconds . 's';
                        } elseif ($downtime_minutes > 0) {
                            $downtimemsg = $downtime_minutes . 'm ' . $downtime_seconds . 's';
                        } else {
                            $downtimemsg = $downtime_seconds . 's ';
                        }
                    }
                    $subject = read_config_option('thold_up_subject');
                    if ($subject == '') {
                        $subject = 'Devices Notice: <DESCRIPTION> (<HOSTNAME>) returned from DOWN state';
                    }
                    $subject = str_replace('<HOSTNAME>', $host['hostname'], $subject);
                    $subject = str_replace('<DESCRIPTION>', $host['description'], $subject);
                    $subject = str_replace('<DOWN/UP>', 'UP', $subject);
                    $subject = strip_tags($subject);
                    $msg = read_config_option('thold_up_text');
                    if ($msg == '') {
                        $msg = __('<br>System <DESCRIPTION> (<HOSTNAME>) status: <DOWN/UP><br><br>Current ping response: <CUR_TIME> ms<br>Average system response : <AVG_TIME> ms<br>System availability: <AVAILABILITY><br>Total Checks Since Clear: <TOT_POLL><br>Total Failed Checks: <FAIL_POLL><br>Last Date Checked UP: <LAST_FAIL><br>Devices Previously DOWN for: <DOWNTIME><br><br>Snmp Info:<br>Name - <SNMP_HOSTNAME><br>Location - <SNMP_LOCATION><br>Uptime - <UPTIMETEXT> (<UPTIME> ms)<br>System - <SNMP_SYSTEM><br><br>NOTE: <NOTES>');
                    }
                    $msg = str_replace('<SUBJECT>', $subject, $msg);
                    $msg = str_replace('<HOSTNAME>', $host['hostname'], $msg);
                    $msg = str_replace('<DESCRIPTION>', $host['description'], $msg);
                    $msg = str_replace('<UPTIME>', $snmp_uptime, $msg);
                    $msg = str_replace('<UPTIMETEXT>', $uptimelong, $msg);
                    $msg = str_replace('<DOWNTIME>', $downtimemsg, $msg);
                    $msg = str_replace('<MESSAGE>', '', $msg);
                    $msg = str_replace('<DOWN/UP>', 'UP', $msg);
                    $msg = str_replace('<SNMP_HOSTNAME>', $snmp_hostname, $msg);
                    $msg = str_replace('<SNMP_LOCATION>', $snmp_location, $msg);
                    $msg = str_replace('<SNMP_CONTACT>', $snmp_contact, $msg);
                    $msg = str_replace('<SNMP_SYSTEM>', html_split_string($snmp_system), $msg);
                    $msg = str_replace('<LAST_FAIL>', $host['status_fail_date'], $msg);
                    $msg = str_replace('<AVAILABILITY>', round($host['availability'], 2) . ' %', $msg);
                    $msg = str_replace('<TOT_POLL>', $host['total_polls'], $msg);
                    $msg = str_replace('<FAIL_POLL>', $host['failed_polls'], $msg);
                    $msg = str_replace('<CUR_TIME>', round($host['cur_time'], 2), $msg);
                    $msg = str_replace('<AVG_TIME>', round($host['avg_time'], 2), $msg);
                    $msg = str_replace('<NOTES>', $host['notes'], $msg);
                    $msg = str_replace("\n", '<br>', $msg);
                    switch ($host['thold_send_email']) {
                        case '0':
                            // Disabled
                            $alert_email = '';
                            break;
                        case '1':
                            // Global List
                            break;
                        case '2':
                            // Devices List Only
                            $alert_email = get_thold_notification_emails($host['thold_host_email']);
                            break;
                        case '3':
                            // Global and Devices List
                            $alert_email = $alert_email . ',' . get_thold_notification_emails($host['thold_host_email']);
                            break;
                    }
                    if ($alert_email == '' && $host['thold_send_email'] > 0) {
                        cacti_log('Host[' . $host['id'] . '] Hostname[' . $host['hostname'] . '] WARNING: Can not send a Device recovering email for \'' . $host['description'] . '\' since the \'Alert Email\' setting is not set for Device!', true, 'THOLD');
                    } elseif ($host['thold_send_email'] == '0') {
                        cacti_log('Host[' . $host['id'] . '] Hostname[' . $host['hostname'] . '] NOTE: Did not send a Device recovering email for \'' . $host['description'] . '\', disabled per Device setting!', true, 'THOLD');
                    } elseif ($alert_email != '') {
                        thold_mail($alert_email, '', $subject, $msg, '');
                    }
                }
            }
        }
    }
    // Lets find hosts that are down
    $hosts = db_fetch_assoc_prepared('SELECT *
		FROM host
		WHERE disabled=""
		AND status = ?
		AND status_event_count = ?', array(HOST_DOWN, $ping_failure_count));
    $total_hosts = sizeof($hosts);
    if (count($hosts)) {
        foreach ($hosts as $host) {
            if (api_plugin_is_enabled('maint')) {
                if (plugin_maint_check_cacti_host($host['id'])) {
                    continue;
                }
            }
            $downtime = time() - strtotime($host['status_rec_date']);
            $downtime_days = floor($downtime / 86400);
            $downtime_hours = floor(($downtime - $downtime_days * 86400) / 3600);
            $downtime_minutes = floor(($downtime - $downtime_days * 86400 - $downtime_hours * 3600) / 60);
            $downtime_seconds = $downtime - $downtime_days * 86400 - $downtime_hours * 3600 - $downtime_minutes * 60;
            if ($downtime_days > 0) {
                $downtimemsg = $downtime_days . 'd ' . $downtime_hours . 'h ' . $downtime_minutes . 'm ' . $downtime_seconds . 's ';
            } elseif ($downtime_hours > 0) {
                $downtimemsg = $downtime_hours . 'h ' . $downtime_minutes . 'm ' . $downtime_seconds . 's';
            } elseif ($downtime_minutes > 0) {
                $downtimemsg = $downtime_minutes . 'm ' . $downtime_seconds . 's';
            } else {
                $downtimemsg = $downtime_seconds . 's ';
            }
            $subject = read_config_option('thold_down_subject');
            if ($subject == '') {
                $subject = __('Devices Error: <DESCRIPTION> (<HOSTNAME>) is DOWN');
            }
            $subject = str_replace('<HOSTNAME>', $host['hostname'], $subject);
            $subject = str_replace('<DESCRIPTION>', $host['description'], $subject);
            $subject = str_replace('<DOWN/UP>', 'DOWN', $subject);
            $subject = strip_tags($subject);
            $msg = read_config_option('thold_down_text');
            if ($msg == '') {
                $msg = __('System Error : <DESCRIPTION> (<HOSTNAME>) is <DOWN/UP><br>Reason: <MESSAGE><br><br>Average system response : <AVG_TIME> ms<br>System availability: <AVAILABILITY><br>Total Checks Since Clear: <TOT_POLL><br>Total Failed Checks: <FAIL_POLL><br>Last Date Checked DOWN : <LAST_FAIL><br>Devices Previously UP for: <DOWNTIME><br>NOTE: <NOTES>');
            }
            $msg = str_replace('<SUBJECT>', $subject, $msg);
            $msg = str_replace('<HOSTNAME>', $host['hostname'], $msg);
            $msg = str_replace('<DESCRIPTION>', $host['description'], $msg);
            $msg = str_replace('<UPTIME>', '', $msg);
            $msg = str_replace('<DOWNTIME>', $downtimemsg, $msg);
            $msg = str_replace('<MESSAGE>', $host['status_last_error'], $msg);
            $msg = str_replace('<DOWN/UP>', 'DOWN', $msg);
            $msg = str_replace('<SNMP_HOSTNAME>', '', $msg);
            $msg = str_replace('<SNMP_LOCATION>', '', $msg);
            $msg = str_replace('<SNMP_CONTACT>', '', $msg);
            $msg = str_replace('<SNMP_SYSTEM>', '', $msg);
            $msg = str_replace('<LAST_FAIL>', $host['status_fail_date'], $msg);
            $msg = str_replace('<AVAILABILITY>', round($host['availability'], 2) . ' %', $msg);
            $msg = str_replace('<CUR_TIME>', round($host['cur_time'], 2), $msg);
            $msg = str_replace('<TOT_POLL>', $host['total_polls'], $msg);
            $msg = str_replace('<FAIL_POLL>', $host['failed_polls'], $msg);
            $msg = str_replace('<AVG_TIME>', round($host['avg_time'], 2), $msg);
            $msg = str_replace('<NOTES>', $host['notes'], $msg);
            $msg = str_replace("\n", '<br>', $msg);
            switch ($host['thold_send_email']) {
                case '0':
                    // Disabled
                    $alert_email = '';
                    break;
                case '1':
                    // Global List
                    break;
                case '2':
                    // Devices List Only
                    $alert_email = get_thold_notification_emails($host['thold_host_email']);
                    break;
                case '3':
                    // Global and Devices List
                    $alert_email = $alert_email . ',' . get_thold_notification_emails($host['thold_host_email']);
                    break;
            }
            if ($alert_email == '' && $host['thold_send_email'] > 0) {
                cacti_log('Host[' . $host['id'] . '] Hostname[' . $host['hostname'] . '] WARNING: Can not send a Device down email for \'' . $host['description'] . '\' since the \'Alert Email\' setting is not set for Device!', true, 'THOLD');
            } elseif ($host['thold_send_email'] == '0') {
                cacti_log('Host[' . $host['id'] . '] Hostname[' . $host['hostname'] . '] NOTE: Did not send a Device down email for \'' . $host['description'] . '\', disabled per Device setting!', true, 'THOLD');
            } elseif ($alert_email != '') {
                thold_mail($alert_email, '', $subject, $msg, '');
            }
        }
    }
    // Now lets record all failed hosts
    db_execute('TRUNCATE TABLE plugin_thold_host_failed');
    $hosts = db_fetch_assoc('SELECT id
		FROM host
		WHERE disabled = ""
		AND status != ' . HOST_UP);
    $failed = '';
    if (sizeof($hosts)) {
        foreach ($hosts as $host) {
            if (api_plugin_is_enabled('maint')) {
                if (plugin_maint_check_cacti_host($host['id'])) {
                    continue;
                }
            }
            $failed .= (strlen($failed) ? '), (' : '(') . $host['id'];
        }
        $failed .= ')';
        db_execute("INSERT INTO plugin_thold_host_failed (host_id) VALUES {$failed}");
    }
    return $total_hosts;
}
Beispiel #4
0
function host_edit()
{
    global $colors, $fields_host_edit, $reindex_types;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("id"));
    /* ==================================================== */
    display_output_messages();
    if (!empty($_GET["id"])) {
        $host = db_fetch_row("select * from host where id=" . $_GET["id"]);
        $header_label = "[edit: " . $host["description"] . "]";
    } else {
        $header_label = "[new]";
    }
    if (!empty($host["id"])) {
        ?>
		<table width="100%" align="center">
			<tr>
				<td class="textInfo" colspan="2">
					<?php 
        print $host["description"];
        ?>
 (<?php 
        print $host["hostname"];
        ?>
)
				</td>
			</tr>
			<tr>
				<td class="textHeader">
				<?php 
        if ($host["availability_method"] == AVAIL_SNMP || $host["availability_method"] == AVAIL_SNMP_AND_PING || $host["availability_method"] == AVAIL_SNMP_OR_PING) {
            ?>
					SNMP Information<br>

					<span style="font-size: 10px; font-weight: normal; font-family: monospace;">
					<?php 
            if ($host["snmp_community"] == "" && $host["snmp_username"] == "" || $host["snmp_version"] == 0) {
                print "<span style='color: #ab3f1e; font-weight: bold;'>SNMP not in use</span>\n";
            } else {
                $snmp_system = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.1.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
                /* modify for some system descriptions */
                /* 0000937: System output in hosts.php poor for Alcatel */
                if (substr_count($snmp_system, "00:")) {
                    $snmp_system = str_replace("00:", "", $snmp_system);
                    $snmp_system = str_replace(":", " ", $snmp_system);
                }
                if ($snmp_system == "") {
                    print "<span style='color: #ff0000; font-weight: bold;'>SNMP error</span>\n";
                } else {
                    $snmp_uptime = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.3.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
                    $snmp_hostname = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.5.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
                    $snmp_location = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.6.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
                    $snmp_contact = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.4.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_auth_protocol"], $host["snmp_priv_passphrase"], $host["snmp_priv_protocol"], $host["snmp_context"], $host["snmp_port"], $host["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);
                    print "<strong>System:</strong>" . html_split_string($snmp_system) . "<br>\n";
                    $days = intval($snmp_uptime / (60 * 60 * 24 * 100));
                    $remainder = $snmp_uptime % (60 * 60 * 24 * 100);
                    $hours = intval($remainder / (60 * 60 * 100));
                    $remainder = $remainder % (60 * 60 * 100);
                    $minutes = intval($remainder / (60 * 100));
                    print "<strong>Uptime:</strong> {$snmp_uptime}";
                    print "&nbsp;({$days} days, {$hours} hours, {$minutes} minutes)<br>\n";
                    print "<strong>Hostname:</strong> {$snmp_hostname}<br>\n";
                    print "<strong>Location:</strong> {$snmp_location}<br>\n";
                    print "<strong>Contact:</strong> {$snmp_contact}<br>\n";
                }
            }
            ?>
					</span>
				<?php 
        }
        if ($host["availability_method"] == AVAIL_PING || $host["availability_method"] == AVAIL_SNMP_AND_PING || $host["availability_method"] == AVAIL_SNMP_OR_PING) {
            /* create new ping socket for host pinging */
            $ping = new Net_Ping();
            $ping->host = $host;
            $ping->port = $host["ping_port"];
            /* perform the appropriate ping check of the host */
            if ($ping->ping($host["availability_method"], $host["ping_method"], $host["ping_timeout"], $host["ping_retries"])) {
                $host_down = false;
                $color = "#000000";
            } else {
                $host_down = true;
                $color = "#ff0000";
            }
            ?>
					<br>Ping Results<br>
					<span style="font-size: 10px; font-weight: normal; color: <?php 
            print $color;
            ?>
; font-family: monospace;">
					<?php 
            print $ping->ping_response;
            ?>
					</span>
				<?php 
        } else {
            if ($host["availability_method"] == AVAIL_NONE) {
                ?>
					No Availability Check In Use<br>
				<?php 
            }
        }
        ?>
				</td>
				<td class="textInfo" valign="top">
					<span style="color: #c16921;">*</span><a href="graphs_new.php?host_id=<?php 
        print $host["id"];
        ?>
">Create Graphs for this Host</a><br>
					<span style="color: #c16921;">*</span><a href="data_sources.php?host_id=<?php 
        print $host["id"];
        ?>
&ds_rows=30&filter=&template_id=-1&method_id=-1&page=1">Data Source List</a><br>
					<span style="color: #c16921;">*</span><a href="graphs.php?host_id=<?php 
        print $host["id"];
        ?>
&graph_rows=30&filter=&template_id=-1&page=1">Graph List</a>
				</td>
			</tr>
		</table>
		<?php 
    }
    html_start_box("<strong>Devices</strong> {$header_label}", "100%", $colors["header"], "3", "center", "");
    /* preserve the host template id if passed in via a GET variable */
    if (!empty($_GET["host_template_id"])) {
        $fields_host_edit["host_template_id"]["value"] = $_GET["host_template_id"];
    }
    draw_edit_form(array("config" => array("form_name" => "chk"), "fields" => inject_form_variables($fields_host_edit, isset($host) ? $host : array())));
    html_end_box();
    ?>
	<script type="text/javascript">
	<!--

	// default snmp information
	var snmp_community       = document.getElementById('snmp_community').value;
	var snmp_username        = document.getElementById('snmp_username').value;
	var snmp_password        = document.getElementById('snmp_password').value;
	var snmp_auth_protocol   = document.getElementById('snmp_auth_protocol').value;
	var snmp_priv_passphrase = document.getElementById('snmp_priv_passphrase').value;
	var snmp_priv_protocol   = document.getElementById('snmp_priv_protocol').value;
	var snmp_context         = document.getElementById('snmp_context').value;
	var snmp_port            = document.getElementById('snmp_port').value;
	var snmp_timeout         = document.getElementById('snmp_timeout').value;
	var max_oids             = document.getElementById('max_oids').value;

	// default ping methods
	var ping_method    = document.getElementById('ping_method').value;
	var ping_port      = document.getElementById('ping_port').value;
	var ping_timeout   = document.getElementById('ping_timeout').value;
	var ping_retries   = document.getElementById('ping_retries').value;

	var availability_methods = document.getElementById('availability_method').options;
	var num_methods          = document.getElementById('availability_method').length;
	var selectedIndex        = document.getElementById('availability_method').selectedIndex;

	var agent = navigator.userAgent;
	agent = agent.match("MSIE");

	function setPingVisibility() {
		availability_method = document.getElementById('availability_method').value;
		ping_method         = document.getElementById('ping_method').value;

		/* debugging, uncomment as required */
		//alert("The availability method is '" + availability_method + "'");
		//alert("The ping method is '" + ping_method + "'");

		switch(availability_method) {
		case "0": // none
			document.getElementById('row_ping_method').style.display  = "none";
			document.getElementById('row_ping_port').style.display    = "none";
			document.getElementById('row_ping_timeout').style.display = "none";
			document.getElementById('row_ping_retries').style.display = "none";

			break;
		case "2": // snmp
			document.getElementById('row_ping_method').style.display  = "none";
			document.getElementById('row_ping_port').style.display    = "none";
			document.getElementById('row_ping_timeout').style.display = "";
			document.getElementById('row_ping_retries').style.display = "";

			break;
		default: // ping ok
			switch(ping_method) {
			case "1": // ping icmp
				document.getElementById('row_ping_method').style.display  = "";
				document.getElementById('row_ping_port').style.display    = "none";
				document.getElementById('row_ping_timeout').style.display = "";
				document.getElementById('row_ping_retries').style.display = "";

				break;
			case "2": // ping udp
			case "3": // ping tcp
				document.getElementById('row_ping_method').style.display  = "";
				document.getElementById('row_ping_port').style.display    = "";
				document.getElementById('row_ping_timeout').style.display = "";
				document.getElementById('row_ping_retries').style.display = "";

				break;
			}

			break;
		}
	}

	function addSelectItem(item, formObj) {
		if (agent != "MSIE") {
			formObj.add(item,null); // standards compliant
		}else{
			formObj.add(item);      // IE only
		}
	}

	function setAvailability(type) {
		/* get the availability structure */
		var am=document.getElementById('availability_method');

		/* get current selectedIndex */
		selectedIndex = document.getElementById('availability_method').selectedIndex;

		/* debugging uncomment as required */
		//alert("The selectedIndex is '" + selectedIndex + "'");
		//alert("The array length is '" + am.length + "'");

		switch(type) {
		case "NoSNMP":
			/* remove snmp options */
			if (am.length == 5) {
				am.remove(1);
				am.remove(1);
				am.remove(1);
			}

			/* set the index to something valid, like "ping" */
			if (selectedIndex > 1) {
				am.selectedIndex=1;
			}

			break;
		case "All":
			/* restore all options */
			if (am.length == 2) {
				am.remove(0);
				am.remove(0);

				var a=document.createElement('option');
				var b=document.createElement('option');
				var c=document.createElement('option');
				var d=document.createElement('option');
				var e=document.createElement('option');

				a.value="0";
				a.text="None";
				addSelectItem(a,am);

				b.value="1";
				b.text="Ping and SNMP";
				addSelectItem(b,am);

				e.value="4";
				e.text="Ping or SNMP";
				addSelectItem(e,am);

				c.value="2";
				c.text="SNMP";
				addSelectItem(c,am);

				d.value="3";
				d.text="Ping";
				addSelectItem(d,am);

				/* restore the correct index number */
				if (selectedIndex == 0) {
					am.selectedIndex = 0;
				}else{
					am.selectedIndex = 3;
				}
			}

			break;
		}

		setAvailabilityVisibility(type, am.selectedIndex);
		setPingVisibility();
	}

	function setAvailabilityVisibility(type, selectedIndex) {
		switch(type) {
		case "NoSNMP":
			switch(selectedIndex) {
			case "0": // availability none
				document.getElementById('row_ping_method').style.display="none";
				document.getElementById('ping_method').value=0;

				break;
			case "1": // ping
				document.getElementById('row_ping_method').style.display="";
				document.getElementById('ping_method').value=ping_method;

				break;
			}
		case "All":
			switch(selectedIndex) {
			case "0": // availability none
				document.getElementById('row_ping_method').style.display="none";
				document.getElementById('ping_method').value=0;

				break;
			case "1": // ping and snmp
			case "3": // ping
			case "4": // ping or snmp
				if ((document.getElementById('row_ping_method').style.display == "none") ||
					(document.getElementById('row_ping_method').style.display == undefined)) {
					document.getElementById('ping_method').value=ping_method;
					document.getElementById('row_ping_method').style.display="";
				}

				break;
			case "2": // snmp
				document.getElementById('row_ping_method').style.display="none";
				document.getElementById('ping_method').value="0";

				break;
			}
		}
	}

	function changeHostForm() {
		snmp_version        = document.getElementById('snmp_version').value;

		switch(snmp_version) {
		case "0":
			setAvailability("NoSNMP");
			setSNMP("None");

			break;
		case "1":
		case "2":
			setAvailability("All");
			setSNMP("v1v2");

			break;
		case "3":
			setAvailability("All");
			setSNMP("v3");

			break;
		}
	}

	function setSNMP(snmp_type) {
		switch(snmp_type) {
		case "None":
			document.getElementById('row_snmp_username').style.display        = "none";
			document.getElementById('row_snmp_password').style.display        = "none";
			document.getElementById('row_snmp_community').style.display       = "none";
			document.getElementById('row_snmp_auth_protocol').style.display   = "none";
			document.getElementById('row_snmp_priv_passphrase').style.display = "none";
			document.getElementById('row_snmp_priv_protocol').style.display   = "none";
			document.getElementById('row_snmp_context').style.display         = "none";
			document.getElementById('row_snmp_port').style.display            = "none";
			document.getElementById('row_snmp_timeout').style.display         = "none";
			document.getElementById('row_max_oids').style.display             = "none";

			break;
		case "v1v2":
			document.getElementById('row_snmp_username').style.display        = "none";
			document.getElementById('row_snmp_password').style.display        = "none";
			document.getElementById('row_snmp_community').style.display       = "";
			document.getElementById('row_snmp_auth_protocol').style.display   = "none";
			document.getElementById('row_snmp_priv_passphrase').style.display = "none";
			document.getElementById('row_snmp_priv_protocol').style.display   = "none";
			document.getElementById('row_snmp_context').style.display         = "none";
			document.getElementById('row_snmp_port').style.display            = "";
			document.getElementById('row_snmp_timeout').style.display         = "";
			document.getElementById('row_max_oids').style.display             = "";

			break;
		case "v3":
			document.getElementById('row_snmp_username').style.display        = "";
			document.getElementById('row_snmp_password').style.display        = "";
			document.getElementById('row_snmp_community').style.display       = "none";
			document.getElementById('row_snmp_auth_protocol').style.display   = "";
			document.getElementById('row_snmp_priv_passphrase').style.display = "";
			document.getElementById('row_snmp_priv_protocol').style.display   = "";
			document.getElementById('row_snmp_context').style.display         = "";
			document.getElementById('row_snmp_port').style.display            = "";
			document.getElementById('row_snmp_timeout').style.display         = "";
			document.getElementById('row_max_oids').style.display             = "";

			break;
		}
	}

	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}

	addLoadEvent(changeHostForm);

	-->
	</script>
	<?php 
    if (isset($_GET["display_dq_details"]) && isset($_SESSION["debug_log"]["data_query"])) {
        html_start_box("<strong>Data Query Debug Information</strong>", "100%", $colors["header"], "3", "center", "");
        print "<tr><td><span style='font-family: monospace;'>" . debug_log_return("data_query") . "</span></td></tr>";
        html_end_box();
    }
    if (!empty($host["id"])) {
        html_start_box("<strong>Associated Graph Templates</strong>", "100%", $colors["header"], "3", "center", "");
        html_header(array("Graph Template Name", "Status"), 2);
        $selected_graph_templates = db_fetch_assoc("select\n\t\t\tgraph_templates.id,\n\t\t\tgraph_templates.name\n\t\t\tfrom (graph_templates,host_graph)\n\t\t\twhere graph_templates.id=host_graph.graph_template_id\n\t\t\tand host_graph.host_id=" . $_GET["id"] . "\n\t\t\torder by graph_templates.name");
        $available_graph_templates = db_fetch_assoc("SELECT\n\t\t\tgraph_templates.id, graph_templates.name\n\t\t\tFROM snmp_query_graph RIGHT JOIN graph_templates\n\t\t\tON (snmp_query_graph.graph_template_id = graph_templates.id)\n\t\t\tWHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name");
        $i = 0;
        if (sizeof($selected_graph_templates) > 0) {
            foreach ($selected_graph_templates as $item) {
                $i++;
                /* get status information for this graph template */
                $is_being_graphed = sizeof(db_fetch_assoc("select id from graph_local where graph_template_id=" . $item["id"] . " and host_id=" . $_GET["id"])) > 0 ? true : false;
                ?>
			<tr>
				<td style="padding: 4px;">
					<strong><?php 
                print $i;
                ?>
)</strong> <?php 
                print $item["name"];
                ?>
				</td>
				<td>
					<?php 
                print $is_being_graphed == true ? "<span style='color: green;'>Is Being Graphed</span> (<a href='graphs.php?action=graph_edit&id=" . db_fetch_cell("select id from graph_local where graph_template_id=" . $item["id"] . " and host_id=" . $_GET["id"] . " limit 0,1") . "'>Edit</a>)" : "<span style='color: #484848;'>Not Being Graphed</span>";
                ?>
				</td>
				<td align='right' nowrap>
					<a href='host.php?action=gt_remove&id=<?php 
                print $item["id"];
                ?>
&host_id=<?php 
                print $_GET["id"];
                ?>
'><img src='images/delete_icon_large.gif' title='Delete Graph Template Association' alt='Delete Graph Template Association' border='0' align='absmiddle'></a>
				</td>
			</tr>
			<?php 
            }
        } else {
            print "<tr><td><em>No associated graph templates.</em></td></tr>";
        }
        ?>
		<tr bgcolor="#<?php 
        print $colors["form_alternate1"];
        ?>
">
			<td colspan="4">
				<table cellspacing="0" cellpadding="1" width="100%">
					<td nowrap>Add Graph Template:&nbsp;
						<?php 
        form_dropdown("graph_template_id", $available_graph_templates, "name", "id", "", "", "");
        ?>
					</td>
					<td align="right">
						&nbsp;<input type="image" src="images/button_add.gif" alt="Add" name="add_gt" align="absmiddle">
					</td>
				</table>
			</td>
		</tr>

		<?php 
        html_end_box();
        html_start_box("<strong>Associated Data Queries</strong>", "100%", $colors["header"], "3", "center", "");
        html_header(array("Data Query Name", "Debugging", "Re-Index Method", "Status"), 2);
        $selected_data_queries = db_fetch_assoc("select\n\t\t\tsnmp_query.id,\n\t\t\tsnmp_query.name,\n\t\t\thost_snmp_query.reindex_method\n\t\t\tfrom (snmp_query,host_snmp_query)\n\t\t\twhere snmp_query.id=host_snmp_query.snmp_query_id\n\t\t\tand host_snmp_query.host_id=" . $_GET["id"] . "\n\t\t\torder by snmp_query.name");
        $available_data_queries = db_fetch_assoc("select\n\t\t\tsnmp_query.id,\n\t\t\tsnmp_query.name\n\t\t\tfrom snmp_query\n\t\t\torder by snmp_query.name");
        $keeper = array();
        foreach ($available_data_queries as $item) {
            if (sizeof(db_fetch_assoc("SELECT snmp_query_id FROM host_snmp_query " . " WHERE ((host_id=" . $_GET["id"] . ")" . " and (snmp_query_id=" . $item["id"] . "))")) > 0) {
                /* do nothing */
            } else {
                array_push($keeper, $item);
            }
        }
        $available_data_queries = $keeper;
        $i = 0;
        if (sizeof($selected_data_queries) > 0) {
            foreach ($selected_data_queries as $item) {
                $i++;
                /* get status information for this data query */
                $num_dq_items = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"]));
                $num_dq_rows = sizeof(db_fetch_assoc("select snmp_index from host_snmp_cache where host_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"] . " group by snmp_index"));
                $status = "success";
                ?>
			<tr>
				<td style="padding: 4px;">
					<strong><?php 
                print $i;
                ?>
)</strong> <?php 
                print $item["name"];
                ?>
				</td>
				<td>
					(<a href="host.php?action=query_verbose&id=<?php 
                print $item["id"];
                ?>
&host_id=<?php 
                print $_GET["id"];
                ?>
">Verbose Query</a>)
				</td>
				<td>
					<?php 
                print $reindex_types[$item["reindex_method"]];
                ?>
				</td>
				<td>
					<?php 
                print $status == "success" ? "<span style='color: green;'>Success</span>" : "<span style='color: green;'>Fail</span>";
                ?>
 [<?php 
                print $num_dq_items;
                ?>
 Item<?php 
                print $num_dq_items == 1 ? "" : "s";
                ?>
, <?php 
                print $num_dq_rows;
                ?>
 Row<?php 
                print $num_dq_rows == 1 ? "" : "s";
                ?>
]
				</td>
				<td align='right' nowrap>
					<a href='host.php?action=query_reload&id=<?php 
                print $item["id"];
                ?>
&host_id=<?php 
                print $_GET["id"];
                ?>
'><img src='images/reload_icon_small.gif' title='Reload Data Query' alt='Reload Data Query' border='0' align='absmiddle'></a>&nbsp;
					<a href='host.php?action=query_remove&id=<?php 
                print $item["id"];
                ?>
&host_id=<?php 
                print $_GET["id"];
                ?>
'><img src='images/delete_icon_large.gif' title='Delete Data Query Association' alt='Delete Data Query Association' border='0' align='absmiddle'></a>
				</td>
			</tr>
			<?php 
            }
        } else {
            print "<tr><td><em>No associated data queries.</em></td></tr>";
        }
        ?>
		<tr bgcolor="#<?php 
        print $colors["form_alternate1"];
        ?>
">
			<td colspan="5">
				<table cellspacing="0" cellpadding="1" width="100%">
					<td nowrap>Add Data Query:&nbsp;
						<?php 
        form_dropdown("snmp_query_id", $available_data_queries, "name", "id", "", "", "");
        ?>
					</td>
					<td nowrap>Re-Index Method:&nbsp;
						<?php 
        form_dropdown("reindex_method", $reindex_types, "", "", read_config_option("reindex_method"), "", "");
        ?>
					</td>
					<td align="right">
						&nbsp;<input type="image" src="images/button_add.gif" alt="Add" name="add_dq" align="absmiddle">
					</td>
				</table>
			</td>
		</tr>

		<?php 
        html_end_box();
    }
    form_save_button("host.php");
}
Beispiel #5
0
function device_display_general($device, $device_text) {
	global $colors;
	require(CACTI_BASE_PATH . "/include/data_query/data_query_arrays.php");
	require_once(CACTI_BASE_PATH . "/lib/device/device_info.php");

	if (isset($device["id"])) {
		html_start_box($device_text, "100", $colors["header"], "3", "center", "", true);
		?>
			<tr>
				<?php if (($device["availability_method"] == AVAIL_SNMP) ||
					($device["availability_method"] == AVAIL_SNMP_AND_PING) ||
					($device["availability_method"] == AVAIL_SNMP_OR_PING)) { ?>
				<td class="textInfo">
					<?php print __("SNMP Information");?><br>
					<span class="normal">
					<?php
					if ((($device["snmp_community"] == "") && ($device["snmp_username"] == "")) ||
						($device["snmp_version"] == 0)) {
						print "<span class=\"info\">SNMP not in use</span>\n";
					}else{
						$snmp_system = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.1.0", $device["snmp_version"],
							$device["snmp_username"], $device["snmp_password"],
							$device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"],
							$device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], read_config_option("snmp_retries"),SNMP_WEBUI);

						/* modify for some system descriptions */
						/* 0000937: System output in devices.php poor for Alcatel */
						if (substr_count($snmp_system, "00:")) {
							$snmp_system = str_replace("00:", "", $snmp_system);
							$snmp_system = str_replace(":", " ", $snmp_system);
						}

						if ($snmp_system == "") {
							print "<span class=\"warning\">SNMP error</span>\n";
						}else{
							$snmp_uptime   = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.3.0", $device["snmp_version"],
								$device["snmp_username"], $device["snmp_password"],
								$device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"],
								$device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);

							$snmp_hostname = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.5.0", $device["snmp_version"],
								$device["snmp_username"], $device["snmp_password"],
								$device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"],
								$device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);

							$snmp_location = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.6.0", $device["snmp_version"],
								$device["snmp_username"], $device["snmp_password"],
								$device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"],
								$device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);

							$snmp_contact  = cacti_snmp_get($device["hostname"], $device["snmp_community"], ".1.3.6.1.2.1.1.4.0", $device["snmp_version"],
								$device["snmp_username"], $device["snmp_password"],
								$device["snmp_auth_protocol"], $device["snmp_priv_passphrase"], $device["snmp_priv_protocol"],
								$device["snmp_context"], $device["snmp_port"], $device["snmp_timeout"], read_config_option("snmp_retries"), SNMP_WEBUI);

							print "<strong>System:</strong> " . html_split_string($snmp_system,200) . "<br>\n";
							$days      = intval($snmp_uptime / (60*60*24*100));
							$remainder = $snmp_uptime % (60*60*24*100);
							$hours     = intval($remainder / (60*60*100));
							$remainder = $remainder % (60*60*100);
							$minutes   = intval($remainder / (60*100));
							print "<strong>" . __("Uptime:")   . " </strong> $snmp_uptime";
							print "&nbsp;($days days, $hours hours, $minutes minutes)<br>\n";
							print "<strong>" . __("Hostname:") . " </strong> $snmp_hostname<br>\n";
							print "<strong>" . __("Location:") . " </strong> $snmp_location<br>\n";
							print "<strong>" . __("Contact:")  . " </strong> $snmp_contact<br>\n";
						}
					}
					?>
					</span>
				</td>
				<?php }
				if (($device["availability_method"] == AVAIL_PING) ||
					($device["availability_method"] == AVAIL_SNMP_AND_PING) ||
					($device["availability_method"] == AVAIL_SNMP_OR_PING)) {
					/* create new ping socket for device pinging */
					$ping = new Net_Ping;

					$ping->device = $device;
					$ping->port = $device["ping_port"];

					/* perform the appropriate ping check of the device */
					if ($ping->ping($device["availability_method"], $device["ping_method"],
						$device["ping_timeout"], $device["ping_retries"])) {
						$device_down = false;
						$ping_class = "ping";
						}else{
						$device_down = true;
						$ping_class = "ping_warning";
						}

				?>
				<td class="textInfo" style="vertical-align:top;">
					<?php print __("Ping Results");?><br>
					<span class="<?php $ping_class ?>">
					<?php print $ping->ping_response; ?>
					</span>
				</td>
				<?php }else if ($device["availability_method"] == AVAIL_NONE) { ?>
				<td class="textInfo">
					<?php print __("No Availability Check In Use");?><br>
				</td>
				<?php } ?>
			</tr>
		<?php
	}else{
		html_start_box($device_text, "100", $colors["header"], "3", "center", "", false);
	}

	html_end_box(FALSE);

	print "<form method='post' action='" .  basename($_SERVER["PHP_SELF"]) . "' name='device_edit_settings'>\n";
	html_start_box("<strong>" . __("General Settings") . "</strong>", "100", $colors["header"], 0, "center", "", true);
	$header_items = array(__("Field"), __("Value"));
	print "<tr><td>";
	html_header($header_items, 1, true, 'device');

	/* preserve the device template id if passed in via a GET variable */
	$fields_device_edit = device_form_list();
	if (!empty($_GET["template_id"])) {
//		$fields_device_edit["device_template_id"]["value"] = $_GET["template_id"];
//		$fields_device_edit["device_template_id"]["method"] = "hidden";
	}

	/* if we are creating a device and have changed templates set that value */
	if (!isset($device["id"])) {
		if (!empty($_GET["template_id"])) {
			$device["device_template_id"] = $_GET["template_id"];
		}
	}

	/* draw basic fields only on first run for a new device */
	draw_edit_form(array(
		"config" => array("form_name" => "chk", "no_form_tag" => true),
		"fields" => inject_form_variables($fields_device_edit, (is_array($device) ? $device : array()))
		));

	/* if the device is new, check/set the $device array with some template values */
	$override_permitted  = true;
	$propagation_allowed = false;
	if (!isset($device["id"])) {
		$template_settings = db_fetch_row("SELECT * FROM device_template WHERE id=" . $_REQUEST["template_id"]);
		if (sizeof($template_settings)) {
		foreach($template_settings as $key => $value) {
			switch($key) {
				case "id":
				case "name":
				case "description":
				case "hash":
				case "image":
					unset($template_settings[$key]);
					break;
				case "override_defaults":
					if ($value == CHECKED) {
						$propagation_allowed = true;
					}
					unset($template_settings[$key]);
					break;
				case "override_permitted":
					if ($value != CHECKED) {
						$override_permitted = false;
					}
					break;
				default:
					break;
			}
		}
		}
	}else{
		if (db_fetch_cell("SELECT override_defaults FROM device_template WHERE id=" . $device["device_template_id"]) == CHECKED) {
			$propagation_allowed = true;
		}
	}

	/* for a given device, display all availability options as well */
	draw_edit_form(array(
		"config" => array("form_name" => "chk", "no_form_tag" => true),
		"fields" => inject_form_variables(device_availability_form_list(), (isset($template_settings) ? $template_settings : $device))
		));

	print "</table></td></tr>";		/* end of html_header */
	html_end_box(!isset($device["id"]));
	form_hidden_box("id", (isset($device["id"]) ? $device["id"] : "0"), "");
	form_hidden_box("hidden_device_template_id", (isset($device["device_template_id"]) ? $device["device_template_id"] : "0"), "");
	form_hidden_box("save_basic_device", "1", "");
	form_hidden_box("save_component_device", "1", "");
	form_hidden_box("override_permitted", ($override_permitted ? "true":"false"), "");
	form_hidden_box("propagation_allowed", ($propagation_allowed ? "true":"false"), "");

	/* javascript relates to availability options, so include it only for existing devices */
	?>
	<script type="text/javascript">
	<!--

	// default snmp information
	var snmp_community       = document.getElementById('snmp_community').value;
	var snmp_username        = document.getElementById('snmp_username').value;
	var snmp_password        = document.getElementById('snmp_password').value;
	var snmp_auth_protocol   = document.getElementById('snmp_auth_protocol').value;
	var snmp_priv_passphrase = document.getElementById('snmp_priv_passphrase').value;
	var snmp_priv_protocol   = document.getElementById('snmp_priv_protocol').value;
	var snmp_context         = document.getElementById('snmp_context').value;
	var snmp_port            = document.getElementById('snmp_port').value;
	var snmp_timeout         = document.getElementById('snmp_timeout').value;
	var max_oids             = document.getElementById('max_oids').value;

	// default ping methods
	var ping_method    = document.getElementById('ping_method').value;
	var ping_port      = document.getElementById('ping_port').value;
	var ping_timeout   = document.getElementById('ping_timeout').value;
	var ping_retries   = document.getElementById('ping_retries').value;

	var availability_methods = document.getElementById('availability_method').options;
	var num_methods          = document.getElementById('availability_method').length;
	var selectedIndex        = document.getElementById('availability_method').selectedIndex;

	var agent = navigator.userAgent;
	agent = agent.match("MSIE");

	function setPingVisibility() {
		availability_method = document.getElementById('availability_method').value;
		ping_method         = document.getElementById('ping_method').value;

		/* debugging, uncomment as required */
		//alert("The availability method is '" + availability_method + "'");
		//alert("The ping method is '" + ping_method + "'");

		switch(availability_method) {
		case "0": // none
			document.getElementById('row_ping_method').style.display  = "none";
			document.getElementById('row_ping_port').style.display    = "none";
			document.getElementById('row_ping_timeout').style.display = "none";
			document.getElementById('row_ping_retries').style.display = "none";

			break;
		case "2": // snmp
			document.getElementById('row_ping_method').style.display  = "none";
			document.getElementById('row_ping_port').style.display    = "none";
			document.getElementById('row_ping_timeout').style.display = "";
			document.getElementById('row_ping_retries').style.display = "";

			break;
		default: // ping ok
			switch(ping_method) {
			case "1": // ping icmp
				document.getElementById('row_ping_method').style.display  = "";
				document.getElementById('row_ping_port').style.display    = "none";
				document.getElementById('row_ping_timeout').style.display = "";
				document.getElementById('row_ping_retries').style.display = "";

				break;
			case "2": // ping udp
			case "3": // ping tcp
				document.getElementById('row_ping_method').style.display  = "";
				document.getElementById('row_ping_port').style.display    = "";
				document.getElementById('row_ping_timeout').style.display = "";
				document.getElementById('row_ping_retries').style.display = "";

				break;
			}

			break;
		}
	}

	function addSelectItem(item, formObj) {
		if (agent != "MSIE") {
			formObj.add(item,null); // standards compliant
		}else{
			formObj.add(item);      // IE only
		}
	}

	function setAvailability(type) {
		/* get the availability structure */
		var am=document.getElementById('availability_method');

		/* get current selectedIndex */
		selectedIndex = document.getElementById('availability_method').selectedIndex;

		/* debugging uncomment as required */
		//alert("The selectedIndex is '" + selectedIndex + "'");
		//alert("The array length is '" + am.length + "'");

		switch(type) {
		case "NoSNMP":
			/* remove snmp options */
			if (am.length == 4) {
				am.remove(1);
				am.remove(1);
				am.remove(1);
			}

			/* set the index to something valid, like "ping" */
			if (selectedIndex > 1) {
				am.selectedIndex=1;
			}

			break;
		case "All":
			/* restore all options */
			if (am.length == 2) {
				am.remove(0);
				am.remove(0);

				var a=document.createElement('option');
				var b=document.createElement('option');
				var c=document.createElement('option');
				var d=document.createElement('option');
				var e=document.createElement('option');

				a.value="0";
				a.text="None";
				addSelectItem(a,am);

				b.value="1";
				b.text="Ping and SNMP";
				addSelectItem(b,am);

				e.value="4";
				e.text="Ping or SNMP";
				addSelectItem(e,am);

				c.value="2";
				c.text="SNMP";
				addSelectItem(c,am);

				d.value="3";
				d.text="Ping";
				addSelectItem(d,am);

				/* restore the correct index number */
				if (selectedIndex == 0) {
					am.selectedIndex = 0;
				}else{
					am.selectedIndex = 3;
				}
			}

			break;
		}

		setAvailabilityVisibility(type, am.selectedIndex);
		setPingVisibility();
	}

	function setAvailabilityVisibility(type, selectedIndex) {
		switch(type) {
		case "NoSNMP":
			switch(selectedIndex) {
			case "0": // availability none
				document.getElementById('row_ping_method').style.display="none";
				document.getElementById('ping_method').value=0;

				break;
			case "1": // ping
				document.getElementById('row_ping_method').style.display="";
				document.getElementById('ping_method').value=ping_method;

				break;
			}
		case "All":
			switch(selectedIndex) {
			case "0": // availability none
				document.getElementById('row_ping_method').style.display="none";
				document.getElementById('ping_method').value=0;

				break;
			case "1": // ping and snmp
			case "3": // ping
			case "4": // ping or snmp
				if ((document.getElementById('row_ping_method').style.display == "none") ||
					(document.getElementById('row_ping_method').style.display == undefined)) {
					document.getElementById('ping_method').value=ping_method;
					document.getElementById('row_ping_method').style.display="";
				}

				break;
			case "2": // snmp
				document.getElementById('row_ping_method').style.display="none";
				document.getElementById('ping_method').value="0";

				break;
			}
		}
	}

	function changeHostForm() {
		snmp_version        = document.getElementById('snmp_version').value;

		switch(snmp_version) {
		case "0":
			setAvailability("NoSNMP");
			setSNMP("None");

			break;
		case "1":
		case "2":
			setAvailability("All");
			setSNMP("v1v2");

			break;
		case "3":
			setAvailability("All");
			setSNMP("v3");

			break;
		}
	}

	function setSNMP(snmp_type) {
		switch(snmp_type) {
		case "None":
			document.getElementById('row_snmp_username').style.display        = "none";
			document.getElementById('row_snmp_password').style.display        = "none";
			document.getElementById('row_snmp_community').style.display       = "none";
			document.getElementById('row_snmp_auth_protocol').style.display   = "none";
			document.getElementById('row_snmp_priv_passphrase').style.display = "none";
			document.getElementById('row_snmp_priv_protocol').style.display   = "none";
			document.getElementById('row_snmp_context').style.display         = "none";
			document.getElementById('row_snmp_port').style.display            = "none";
			document.getElementById('row_snmp_timeout').style.display         = "none";
			document.getElementById('row_max_oids').style.display             = "none";

			break;
		case "v1v2":
			document.getElementById('row_snmp_username').style.display        = "none";
			document.getElementById('row_snmp_password').style.display        = "none";
			document.getElementById('row_snmp_community').style.display       = "";
			document.getElementById('row_snmp_auth_protocol').style.display   = "none";
			document.getElementById('row_snmp_priv_passphrase').style.display = "none";
			document.getElementById('row_snmp_priv_protocol').style.display   = "none";
			document.getElementById('row_snmp_context').style.display         = "none";
			document.getElementById('row_snmp_port').style.display            = "";
			document.getElementById('row_snmp_timeout').style.display         = "";
			document.getElementById('row_max_oids').style.display             = "";

			break;
		case "v3":
			document.getElementById('row_snmp_username').style.display        = "";
			document.getElementById('row_snmp_password').style.display        = "";
			document.getElementById('row_snmp_community').style.display       = "none";
			document.getElementById('row_snmp_auth_protocol').style.display   = "";
			document.getElementById('row_snmp_priv_passphrase').style.display = "";
			document.getElementById('row_snmp_priv_protocol').style.display   = "";
			document.getElementById('row_snmp_context').style.display         = "";
			document.getElementById('row_snmp_port').style.display            = "";
			document.getElementById('row_snmp_timeout').style.display         = "";
			document.getElementById('row_max_oids').style.display             = "";

			break;
		}
	}

	function toggleAvailabilityAndSnmp(template_enabled) {
		if (!template_enabled && $('#override_permitted').val() == 'true') {
			$('#override_permitted').removeAttr("disabled");
			$('#availability_header').removeAttr("disabled");
			$('#availability_method').removeAttr("disabled");
			$('#ping_method').removeAttr("disabled");
			$('#ping_port').removeAttr("disabled");
			$('#ping_timeout').removeAttr("disabled");
			$('#ping_retries').removeAttr("disabled");
			$('#snmp_spacer').removeAttr("disabled");
			$('#snmp_version').removeAttr("disabled");
			$('#snmp_username').removeAttr("disabled");
			$('#snmp_password').removeAttr("disabled");
			$('#snmp_password_confirm').removeAttr("disabled");
			$('#snmp_community').removeAttr("disabled");
			$('#snmp_auth_protocol').removeAttr("disabled");
			$('#snmp_priv_passphrase').removeAttr("disabled");
			$('#snmp_priv_protocol').removeAttr("disabled");
			$('#snmp_context').removeAttr("disabled");
			$('#snmp_port').removeAttr("disabled");
			$('#snmp_timeout').removeAttr("disabled");
			$('#max_oids').removeAttr("disabled");
			$('#device_threads').removeAttr("disabled");
		}else{
			$('#override_permitted').attr("disabled","disabled");
			$('#availability_header').attr("disabled","disabled");
			$('#availability_method').attr("disabled","disabled");
			$('#ping_method').attr("disabled","disabled");
			$('#ping_port').attr("disabled","disabled");
			$('#ping_timeout').attr("disabled","disabled");
			$('#ping_retries').attr("disabled","disabled");
			$('#snmp_spacer').attr("disabled","disabled");
			$('#snmp_version').attr("disabled","disabled");
			$('#snmp_username').attr("disabled","disabled");
			$('#snmp_password').attr("disabled","disabled");
			$('#snmp_password_confirm').attr("disabled","disabled");
			$('#snmp_community').attr("disabled","disabled");
			$('#snmp_auth_protocol').attr("disabled","disabled");
			$('#snmp_priv_passphrase').attr("disabled","disabled");
			$('#snmp_priv_protocol').attr("disabled","disabled");
			$('#snmp_context').attr("disabled","disabled");
			$('#snmp_port').attr("disabled","disabled");
			$('#snmp_timeout').attr("disabled","disabled");
			$('#max_oids').attr("disabled","disabled");
			$('#device_threads').attr("disabled","disabled");
		}

		changeHostForm();

		if ($('#override_permitted').val() == 'false') {
			$('#template_enabled').attr("checked","checked");
			$('#template_enabled').attr("disabled","disabled");
		}

		if ($('#propagation_allowed').val() == 'false') {
			$('#row_template_enabled').hide();
		}else{
			$('#row_template_enabled').show();
		}
	}

	$().ready(function() {
		toggleAvailabilityAndSnmp(document.getElementById('template_enabled').checked);

		/* Hide options when override is turned off */
		$("#template_enabled").change(function () {
			toggleAvailabilityAndSnmp(this.checked);
		});

		if ($('#id').val() == 0) {
			$('#device_template_id').change(function() {
				document.location='devices.php?action=edit&template_id='+this.value+'&status=-1'
			});
		}
	});

	-->
	</script>
	<?php

	if ((isset($_GET["display_dq_details"])) && (isset($_SESSION["debug_log"]["data_query"]))) {
		html_start_box("<strong>" . __("Data Query Debug Information") . "</strong>", "100", $colors["header"], "3", "center", "", true);

		print "<tr><td><span class=\"log\">" . debug_log_return("data_query") . "</span></td></tr>";

		html_end_box(false);
	}

	if (isset($device["id"])) {
		html_start_box("<strong>". __("Associated Graph Templates") . "</strong>", "100", $colors["header"], 0, "center", "", true);
		print "<tr><td>";
		html_header(array(__("Graph Template Name"), __("Status")), 2);

		$selected_graph_templates = db_fetch_assoc("select
			graph_templates.id,
			graph_templates.name
			from (graph_templates,device_graph)
			where graph_templates.id=device_graph.graph_template_id
			and device_graph.device_id=" . $_GET["id"] . "
			order by graph_templates.name");

		$available_graph_templates = db_fetch_assoc("SELECT
			graph_templates.id, graph_templates.name
			FROM snmp_query_graph RIGHT JOIN graph_templates
			ON (snmp_query_graph.graph_template_id = graph_templates.id)
			WHERE (((snmp_query_graph.name) Is Null)) ORDER BY graph_templates.name");

		/* omit those graph_templates, that have already been associated */
		$keeper = array();
		foreach ($available_graph_templates as $item) {
			if (sizeof(db_fetch_assoc("SELECT graph_template_id FROM device_graph " .
					" WHERE ((device_id=" . $_GET["id"] . ")" .
					" AND (graph_template_id=" . $item["id"] ."))")) > 0) {
				/* do nothing */
			} else {
				array_push($keeper, $item);
			}
		}

		$available_graph_templates = $keeper;

		$i = 0;
		if (sizeof($selected_graph_templates) > 0) {
		foreach ($selected_graph_templates as $item) {
			$i++;
			form_alternate_row_color("graph_template" . $i);

			/* get status information for this graph template */
			$is_being_graphed = (sizeof(db_fetch_assoc("select id from graph_local where graph_template_id=" . $item["id"] . " and device_id=" . $_GET["id"])) > 0) ? true : false;

			?>
				<td style="padding: 4px;">
					<strong><?php print $i;?>)</strong> <?php print $item["name"];?>
				</td>
				<td>
					<?php print (($is_being_graphed == true) ? "<span class=\"success\">" . __("Is Being Graphed") . "</span> (<a href='" . htmlspecialchars("graphs.php?action=graph_edit&id=" . db_fetch_cell("select id from graph_local where graph_template_id=" . $item["id"] . " and device_id=" . get_request_var("id") . " limit 0,1")) . "'>" . __("Edit") . "</a>)" : "<span class=\"unknown\">" . __("Not Being Graphed") . "</span>");?>
				</td>
				<td align='right' nowrap>
					<a href='devices.php?action=gt_remove&amp;id=<?php print $item["id"];?>&amp;device_id=<?php print $_GET["id"];?>'><img align='middle' class='buttonSmall' src='images/delete_icon_large.gif' title='<?php print __("Delete Graph Template Association");?>' alt='<?php print __("Delete");?>'></a>
				</td>
			<?php
			form_end_row();
		}
		}else{
			print "<tr><td><em>" . __("No Associated Graph Templates.") . "</em></td></tr>";
		}

		form_alternate_row_color("gt_device" . $device["id"]);
		?>
			<td colspan="4">
				<table cellspacing="0" cellpadding="1" width="100%">
					<tr>
					<td nowrap><?php print __("Add Graph Template:");?>&nbsp;
						<?php form_dropdown("graph_template_id",$available_graph_templates,"name","id","","","");?>
					</td>
					<td align="right">
						&nbsp;<input type="submit" value="<?php print __("Add");?>" name="add_gt_y" align="middle">
					</td>
					</tr>
				</table>
			</td>
		<?php
		form_end_row();
		print "</table></td></tr>";		/* end of html_header */
		html_end_box(FALSE);

		html_start_box("<strong>" . __("Associated Data Queries") . "</strong>", "100", $colors["header"], 0, "center", "", true);
		print "<tr><td>";
		html_header(array(__("Data Query Name"), __("Debugging"), __("Re-Index Method"), __("Status")), 2);

		$selected_data_queries = db_fetch_assoc("select
			snmp_query.id,
			snmp_query.name,
			device_snmp_query.reindex_method
			from (snmp_query,device_snmp_query)
			where snmp_query.id=device_snmp_query.snmp_query_id
			and device_snmp_query.device_id=" . $_GET["id"] . "
			order by snmp_query.name");

		$available_data_queries = db_fetch_assoc("select
			snmp_query.id,
			snmp_query.name
			from snmp_query
			order by snmp_query.name");

		$keeper = array();
		foreach ($available_data_queries as $item) {
			if (sizeof(db_fetch_assoc("SELECT snmp_query_id FROM device_snmp_query " .
					" WHERE ((device_id=" . $_GET["id"] . ")" .
					" and (snmp_query_id=" . $item["id"] ."))")) > 0) {
				/* do nothing */
			} else {
				array_push($keeper, $item);
			}
		}

		$available_data_queries = $keeper;

		$i = 0;
		if (sizeof($selected_data_queries) > 0) {
			foreach ($selected_data_queries as $item) {
				$i++;
				form_alternate_row_color("selected_data_queries" . $i);

				/* get status information for this data query */
				$num_dq_items = sizeof(db_fetch_assoc("select snmp_index from device_snmp_cache where device_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"]));
				$num_dq_rows = sizeof(db_fetch_assoc("select snmp_index from device_snmp_cache where device_id=" . $_GET["id"] . " and snmp_query_id=" . $item["id"] . " group by snmp_index"));

				$status = "success";

				?>
					<td style="padding: 4px;">
						<strong><?php print $i;?>)</strong> <?php print $item["name"];?>
					</td>
					<td>
						(<a href="devices.php?action=query_verbose&amp;id=<?php print $item["id"];?>&amp;device_id=<?php print $_GET["id"];?>"><?php print __("Verbose Query");?></a>)
					</td>
					<td>
						<?php form_dropdown("reindex_method_device_".get_request_var("id")."_query_".$item["id"]."_method_".$item["reindex_method"],$reindex_types,"","",$item["reindex_method"],"","","","");?>
					</td>
					<td>
						<?php print (($status == "success") ? "<span class=\"success\">" . __("Success") . "</span>" : "<span class=\"fail\">" . __("Fail") . "</span>");?> [<?php print $num_dq_items;?> <?php print __("Item", $num_dq_items);?>, <?php print $num_dq_rows;?> <?php print __("Row", $num_dq_rows);?>]
					</td>
					<td align='right' nowrap>
						<a href='devices.php?action=query_reload&amp;id=<?php print $item["id"];?>&amp;device_id=<?php print $_GET["id"];?>'><img align='middle' class='buttonSmall' src='images/reload_icon_small.gif' title='<?php print __("Reload Data Query");?>' alt='<?php print __("Reload");?>'></a>&nbsp;
						<a href='devices.php?action=query_remove&amp;id=<?php print $item["id"];?>&amp;device_id=<?php print $_GET["id"];?>'><img align='middle' class='buttonSmall' src='images/delete_icon_large.gif' title='<?php print __("Delete Data Query Association");?>' alt='<?php print __("Delete");?>'></a>
					</td>
				<?php
				form_end_row();
			}
		}else{
			print "<tr><td><em>". __("No associated data queries.") . "</em></td></tr>";
		}

		form_alternate_row_color("dq_device" . $device["id"]);

		?>
			<td colspan="5">
				<table cellspacing="0" cellpadding="1" width="100%">
					<tr>
					<td nowrap><?php print __("Add Data Query:");?>&nbsp;
						<?php form_dropdown("snmp_query_id",$available_data_queries,"name","id","","","");?>
					</td>
					<td nowrap><?php print __("Re-Index Method:");?>&nbsp;
						<?php form_dropdown("reindex_method",$reindex_types,"","","1","","");?>
					</td>
					<td align="right">
						&nbsp;<input type="submit" value="<?php print __("Add");?>" name="add_dq_y" align="middle">
					</td>
					</tr>
				</table>
			</td>
		<?php
		form_end_row();
		print "</table></td></tr>";		/* end of html_header */
		html_end_box();
	}

	form_save_button_alt();
}