function add_host_based_graphs()
{
    global $config, $device_hashes, $device_query_hashes, $device_health_hashes;
    debug('Adding Host Based Graphs');
    /* check for host level graphs next data queries */
    $host_cpu_dq = read_config_option('mikrotik_dq_host_cpu');
    $host_users_dq = mikrotik_data_query_by_hash('ce63249e6cc3d52bc69659a3f32194fe');
    $hosts = db_fetch_assoc("SELECT host_id, host.description, host.hostname \n\t\tFROM plugin_mikrotik_system\n\t\tINNER JOIN host\n\t\tON host.id=plugin_mikrotik_system.host_id\n\t\tWHERE host_status IN(0,3) AND host.disabled=''");
    if (sizeof($hosts)) {
        foreach ($hosts as $h) {
            debug('Processing Host: ' . $h['description'] . ' [' . $h['hostname'] . ']');
            foreach ($device_hashes as $hash) {
                $template = mikrotik_template_by_hash($hash);
                if (!empty($template)) {
                    debug('Processing ' . db_fetch_cell_prepared('SELECT name FROM graph_templates WHERE hash = ?', array($hash)));
                    mikrotik_gt_graph($h['host_id'], $template);
                }
            }
            foreach ($device_query_hashes as $hash) {
                $query = mikrotik_data_query_by_hash($hash);
                if (!empty($query)) {
                    debug('Processing ' . db_fetch_cell_prepared('SELECT name FROM snmp_query WHERE hash = ?', array($hash)));
                    if ($hash == '7dd90372956af1dc8ec7b859a678f227') {
                        $exclusion = read_config_option('mikrotik_user_exclusion');
                        add_host_dq_graphs($h['host_id'], $query, 'userName', $exclusion, false);
                    } else {
                        add_host_dq_graphs($h['host_id'], $query);
                    }
                }
            }
            $health = db_fetch_row_prepared('SELECT * FROM plugin_mikrotik_system_health WHERE host_id = ?', array($h['host_id']));
            debug('Processing Health');
            if (sizeof($health)) {
                foreach ($device_health_hashes as $column => $hash) {
                    if (!empty($health[$column]) && $health[$column] != 'NULL') {
                        $template = mikrotik_template_by_hash($hash);
                        if (!empty($template)) {
                            debug('Processing ' . db_fetch_cell_prepared('SELECT name FROM graph_templates WHERE hash = ?', array($hash)));
                            mikrotik_gt_graph($h['host_id'], $template);
                        }
                    }
                }
            }
        }
    } else {
        debug('No Hosts Found');
    }
}
function mikrotik_users()
{
    global $config, $colors, $item_rows, $mikrotik_hrSWTypes, $mikrotik_hrSWRunStatus;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('page'));
    input_validate_input_number(get_request_var_request('rows'));
    input_validate_input_number(get_request_var_request('device'));
    /* ==================================================== */
    /* clean up sort_column */
    if (isset($_REQUEST['sort_column'])) {
        $_REQUEST['sort_column'] = sanitize_search_string(get_request_var_request('sort_column'));
    }
    /* clean up sort_direction */
    if (isset($_REQUEST['sort_direction'])) {
        $_REQUEST['sort_direction'] = sanitize_search_string(get_request_var_request('sort_direction'));
    }
    /* clean up filter string */
    if (isset($_REQUEST['filter'])) {
        $_REQUEST['filter'] = sanitize_search_string(get_request_var_request('filter'));
    }
    /* clean up active string */
    if (isset($_REQUEST['active'])) {
        $_REQUEST['active'] = sanitize_search_string(get_request_var_request('active'));
    }
    if (isset($_REQUEST['reset'])) {
        kill_session_var('sess_mikrotik_users_sort_column');
        kill_session_var('sess_mikrotik_users_sort_direction');
        kill_session_var('sess_mikrotik_users_filter');
        kill_session_var('sess_mikrotik_users_active');
        kill_session_var('sess_default_rows');
        kill_session_var('sess_mikrotik_users_device');
        kill_session_var('sess_mikrotik_users_current_page');
    } elseif (isset($_REQUEST['clear'])) {
        kill_session_var('sess_mikrotik_users_sort_column');
        kill_session_var('sess_mikrotik_users_sort_direction');
        kill_session_var('sess_mikrotik_users_filter');
        kill_session_var('sess_mikrotik_users_active');
        kill_session_var('sess_default_rows');
        kill_session_var('sess_mikrotik_users_device');
        kill_session_var('sess_mikrotik_users_current_page');
        unset($_REQUEST['sort_column']);
        unset($_REQUEST['sort_direction']);
        unset($_REQUEST['filter']);
        unset($_REQUEST['active']);
        unset($_REQUEST['rows']);
        unset($_REQUEST['device']);
        unset($_REQUEST['page']);
    } else {
        /* if any of the settings changed, reset the page number */
        $changed = false;
        $changed += mikrotik_check_changed('filter', 'sess_mikrotik_users_filter');
        $changed += mikrotik_check_changed('active', 'sess_mikrotik_users_active');
        $changed += mikrotik_check_changed('rows', 'sess_default_rows');
        $changed += mikrotik_check_changed('device', 'sess_mikrotik_users_device');
        if ($changed) {
            $_REQUEST['page'] = '1';
        }
    }
    load_current_session_value('page', 'sess_mikrotik_users_current_page', '1');
    load_current_session_value('rows', 'sess_default_rows', read_config_option('num_rows_table'));
    load_current_session_value('device', 'sess_mikrotik_users_device', '-1');
    load_current_session_value('sort_column', 'sess_mikrotik_users_sort_column', 'name');
    load_current_session_value('sort_direction', 'sess_mikrotik_users_sort_direction', 'ASC');
    load_current_session_value('filter', 'sess_mikrotik_users_filter', '');
    load_current_session_value('active', 'sess_mikrotik_users_active', 'true');
    ?>
	<script type='text/javascript'>
	function applyFilter() {
		strURL  = '?action=users';
		strURL += '&filter='   + $('#filter').val();
		strURL += '&rows='     + $('#rows').val();
		strURL += '&active='   + $('#active').is(':checked');
		strURL += '&device='   + $('#device').val();
		strURL += '&header=false';
		loadPageNoHeader(strURL);
	}

	function clearFilter() {
		strURL  = '?action=users&clear=&header=false';
		loadPageNoHeader(strURL);
	}

	$(function() {
		$('#form_users').submit(function(event) {
			event.preventDefault();
			applyFilter();
		});
	});
	</script>
	<?php 
    html_start_box('<strong>User Statistics</strong>', '100%', $colors['header'], '3', 'center', '');
    ?>
	<tr class='even noprint'>
		<td>
		<form id='form_users' method='get' action='mikrotik.php?action=users'>
			<table class='filterTable'>
				<tr>
					<td>
						Search
					</td>
					<td>
						<input id='filter' type='text' size='25' value='<?php 
    print htmlspecialchars(get_request_var_request('filter'));
    ?>
'>
					</td>
					<td>
						Device
					</td>
					<td>
						<select id='device' onChange='applyFilter()'>
							<option value='-1'<?php 
    if (get_request_var_request('device') == '-1') {
        ?>
 selected<?php 
    }
    ?>
>All</option>
							<?php 
    $hosts = db_fetch_assoc('SELECT DISTINCT host.id, host.description
								FROM plugin_mikrotik_system AS hrs
								INNER JOIN host
								ON hrs.host_id=host.id
								ORDER BY description');
    if (sizeof($hosts)) {
        foreach ($hosts as $h) {
            echo "<option value='" . $h['id'] . "' " . (get_request_var_request('device') == $h['id'] ? 'selected' : '') . '>' . $h['description'] . '</option>';
        }
    }
    ?>
						</select>
					</td>
					<td>
						Devices
					</td>
					<td>
						<select id='rows' onChange='applyFilter()'>
							<option value="-1"<?php 
    if (get_request_var_request("rows") == "-1") {
        ?>
 selected<?php 
    }
    ?>
>Default</option>
							<?php 
    if (sizeof($item_rows)) {
        foreach ($item_rows as $key => $name) {
            echo "<option value='" . $key . "' " . (get_request_var_request("rows") == $key ? "selected" : "") . ">" . $name . "</option>";
        }
    }
    ?>
						</select>
					</td>
					<td>
						<input type='checkbox' id='active' onChange='applyFilter()' <?php 
    print get_request_var_request('active') == 'true' || get_request_var_request('active') == 'on' ? 'checked' : '';
    ?>
>
					</td>
					<td>
						<label for='active'>Active Users</label>
					</td>
					<td>
						<input type='button' onClick='applyFilter()' value='Go' border='0'>
					</td>
					<td>
						<input type='button' onClick='clearFilter()' value='Clear' name='clear' border='0'>
					</td>
				</tr>
			</table>
			<input type='hidden' id='page' name='page' value='<?php 
    print $_REQUEST['page'];
    ?>
'>
			</form>
		</td>
	</tr>
	<?php 
    html_end_box();
    html_start_box('', '100%', $colors['header'], '3', 'center', '');
    if ($_REQUEST['rows'] == '-1') {
        $num_rows = read_config_option('num_rows_table');
    } else {
        $num_rows = get_request_var_request('rows');
    }
    $limit = ' LIMIT ' . $num_rows * (get_request_var_request('page') - 1) . ',' . $num_rows;
    $sql_where = "WHERE hrswr.name!='' AND hrswr.name!='System Idle Process'";
    if ($_REQUEST['device'] != '-1') {
        $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . ' h.id=' . $_REQUEST['device'];
    }
    if ($_REQUEST['active'] == 'true' || $_REQUEST['active'] == 'on') {
        $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . ' present=1';
    }
    if ($_REQUEST['filter'] != '') {
        $sql_where .= (strlen($sql_where) ? ' AND' : 'WHERE') . " (h.description LIKE '%" . $_REQUEST['filter'] . "%' OR\n\t\t\thrswr.name LIKE '%" . $_REQUEST['filter'] . "%' OR\n\t\t\th.hostname LIKE '%" . $_REQUEST['filter'] . "%')";
    }
    $sql = "SELECT hrswr.*, h.hostname, h.description, h.disabled, \n\t\tbytesIn/connectTime AS avgBytesIn, \n\t\tbytesOut/connectTime AS avgBytesOut\n\t\tFROM plugin_mikrotik_users AS hrswr\n\t\tINNER JOIN host AS h\n\t\tON h.id=hrswr.host_id\n\t\tINNER JOIN plugin_mikrotik_system AS hrs\n\t\tON hrs.host_id=h.id\n\t\t{$sql_where}\n\t\tORDER BY " . get_request_var_request('sort_column') . ' ' . get_request_var_request('sort_direction') . ' ' . $limit;
    //echo $sql;
    $rows = db_fetch_assoc($sql);
    $total_rows = db_fetch_cell("SELECT COUNT(*)\n\t\tFROM plugin_mikrotik_users AS hrswr\n\t\tINNER JOIN host AS h\n\t\tON h.id=hrswr.host_id\n\t\tINNER JOIN plugin_mikrotik_system AS hrs\n\t\tON hrs.host_id=h.id\n\t\t{$sql_where}");
    $nav = html_nav_bar('mikrotik.php?action=users', MAX_DISPLAY_PAGES, get_request_var_request('page'), get_request_var_request('rows'), $total_rows, 14, 'Users', 'page', 'main');
    print $nav;
    $display_text = array('nosort' => array('display' => 'Actions', 'sort' => '', 'align' => 'left'), 'description' => array('display' => 'Hostname', 'sort' => 'ASC', 'align' => 'left'), 'name' => array('display' => 'User', 'sort' => 'DESC', 'align' => 'left'), 'domain' => array('display' => 'Domain', 'sort' => 'ASC', 'align' => 'left'), 'ip' => array('display' => 'IP Address', 'sort' => 'ASC', 'align' => 'left'), 'mac' => array('display' => 'MAC', 'sort' => 'DESC', 'align' => 'left'), 'connectTime' => array('display' => 'Connect Time', 'sort' => 'DESC', 'align' => 'right'), 'curBytesIn' => array('display' => 'Cur In', 'sort' => 'DESC', 'align' => 'right'), 'curBytesOut' => array('display' => 'Cur Out', 'sort' => 'DESC', 'align' => 'right'), 'avgBytesIn' => array('display' => 'Avg In', 'sort' => 'DESC', 'align' => 'right'), 'avgBytesOut' => array('display' => 'Avg Out', 'sort' => 'DESC', 'align' => 'right'), 'bytesIn' => array('display' => 'Total In', 'sort' => 'DESC', 'align' => 'right'), 'bytesOut' => array('display' => 'Total Out', 'sort' => 'DESC', 'align' => 'right'), 'last_seen' => array('display' => 'Last Seen', 'sort' => 'ASC', 'align' => 'right'));
    html_header_sort($display_text, get_request_var_request('sort_column'), get_request_var_request('sort_direction'), 'false');
    if (sizeof($rows)) {
        foreach ($rows as $row) {
            if ($row['present'] == 1) {
                $days = intval($row['connectTime'] / (60 * 60 * 24));
                $remainder = $row['connectTime'] % (60 * 60 * 24);
                $hours = intval($remainder / (60 * 60));
                $remainder = $remainder % (60 * 60);
                $minutes = intval($remainder / 60);
            }
            form_alternate_row();
            if (api_plugin_user_realm_auth('host.php')) {
                $host_url = "<a class='hyperLink' href='" . htmlspecialchars($config['url_path'] . 'host.php?action=edit&id=' . $row['host_id']) . "' title='Edit Hosts'>" . $row['hostname'] . '</a>';
            } else {
                $host_url = $row['hostname'];
            }
            $graphdq = mikrotik_data_query_by_hash('ce63249e6cc3d52bc69659a3f32194fe');
            if (!empty($graphdq)) {
                $graphsurl = mikrotik_get_graph_url($graphdq, $row['host_id'], $row['name'], $row['name'], true);
                echo "<td style='text-align:left;width:60px;'>{$graphsurl}</td>";
            } else {
                echo "<td style='width:60px;'></td>";
            }
            echo "<td style='text-align:left;'><strong>" . (strlen($_REQUEST['filter']) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", $row['description'] . '</strong> [' . $host_url . ']') : $row['description'] . '</strong> [' . $host_url . ']') . '</td>';
            echo "<td style='text-align:left;'>" . (strlen($_REQUEST['filter']) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", $row['name']) : $row['name']) . '</td>';
            echo "<td style='text-align:left;' title='" . htmlspecialchars($row['domain']) . "'>" . (strlen($_REQUEST['filter']) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", $row['domain']) : $row['domain']) . '</td>';
            if ($row['present'] == 1) {
                echo "<td style='text-align:left;' title='" . htmlspecialchars($row['ip']) . "'>" . (strlen($_REQUEST['filter']) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", $row['ip']) : $row['ip']) . '</td>';
                echo "<td style='text-align:left;' title='" . htmlspecialchars($row['mac']) . "'>" . (strlen($_REQUEST['filter']) ? preg_replace('/(' . preg_quote(get_request_var_request('filter'), '/') . ')/i', "<span class='filteredValue'>\\1</span>", $row['mac']) : $row['mac']) . '</td>';
                echo "<td style='text-align:right;'>" . mikrotik_format_uptime($days, $hours, $minutes) . '</td>';
                echo "<td style='text-align:right;'>" . mikrotik_memory($row['curBytesIn'] * 8, 'b/s') . '</td>';
                echo "<td style='text-align:right;'>" . mikrotik_memory($row['curBytesOut'] * 8, 'b/s') . '</td>';
                echo "<td style='text-align:right;'>" . mikrotik_memory($row['avgBytesIn'] * 8, 'b/s') . '</td>';
                echo "<td style='text-align:right;'>" . mikrotik_memory($row['avgBytesOut'] * 8, 'b/s') . '</td>';
                echo "<td style='text-align:right;'>" . mikrotik_memory($row['bytesIn'], 'B') . '</td>';
                echo "<td style='text-align:right;'>" . mikrotik_memory($row['bytesOut'], 'B') . '</td>';
                echo "<td style='text-align:right;'>" . $row['last_seen'] . '</td>';
            } else {
                echo "<td style='text-align:left;'>N/A</td>";
                echo "<td style='text-align:left;'>N/A</td>";
                echo "<td style='text-align:left;'>N/A</td>";
                echo "<td style='text-align:left;'>N/A</td>";
                echo "<td style='text-align:right;'>N/A</td>";
                echo "<td style='text-align:right;'>N/A</td>";
                echo "<td style='text-align:right;'>N/A</td>";
                echo "<td style='text-align:right;'>N/A</td>";
                echo "<td style='text-align:right;'>N/A</td>";
                echo "<td style='text-align:right;'>" . $row['last_seen'] . '</td>';
            }
            form_end_row();
        }
        print $nav;
    } else {
        print '<tr><td colspan="5"><em>No Users Found</em></td></tr>';
    }
    html_end_box();
}
function form_actions()
{
    global $colors, $user_actions, $fields_user_edit;
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_post('drp_action'));
    /* ==================================================== */
    /* if we are to save this form, instead of display it */
    if (isset($_POST['selected_items'])) {
        $selected_items = unserialize(stripslashes($_POST['selected_items']));
        if ($_POST['drp_action'] == '1') {
            /* delete */
            if (!isset($_POST['delete_type'])) {
                $_POST['delete_type'] = 2;
            }
            $data_sources_to_act_on = array();
            $graphs_to_act_on = array();
            $devices_to_act_on = array();
            for ($i = 0; $i < count($selected_items); $i++) {
                /* ================= input validation ================= */
                $selected_items[$i] = sanitize_search_string($selected_items[$i]);
                /* ==================================================== */
                $data_sources = db_fetch_assoc('SELECT
					data_local.id AS local_data_id
					FROM data_local
					WHERE ' . array_to_sql_or($selected_items, 'data_local.snmp_index') . "\n\t\t\t\t\tAND snmp_query_id='" . mikrotik_data_query_by_hash('ce63249e6cc3d52bc69659a3f32194fe') . "'");
                if (sizeof($data_sources) > 0) {
                    foreach ($data_sources as $data_source) {
                        $data_sources_to_act_on[] = $data_source['local_data_id'];
                    }
                }
                $graphs = db_fetch_assoc('SELECT
					graph_local.id AS local_graph_id
					FROM graph_local
					WHERE ' . array_to_sql_or($selected_items, 'graph_local.snmp_index') . "\n\t\t\t\t\tAND snmp_query_id='" . mikrotik_data_query_by_hash('ce63249e6cc3d52bc69659a3f32194fe') . "'");
                if (sizeof($graphs) > 0) {
                    foreach ($graphs as $graph) {
                        $graphs_to_act_on[] = $graph['local_graph_id'];
                    }
                }
                $devices_to_act_on[] = $selected_items[$i];
            }
            api_data_source_remove_multi($data_sources_to_act_on);
            api_graph_remove_multi($graphs_to_act_on);
            db_execute("DELETE FROM plugin_mikrotik_users WHERE name IN ('" . implode("','", $devices_to_act_on) . "')");
        }
        header('Location: mikrotik_users.php&header=false');
        exit;
    }
    /* setup some variables */
    $user_list = '';
    /* loop through each of the user templates selected on the previous page and get more info about them */
    while (list($var, $val) = each($_POST)) {
        if (preg_match('/^chk_([A-Z0-9]+)$/', $var, $matches)) {
            /* ================= input validation ================= */
            $matches[1] = sanitize_search_string($matches[1]);
            /* ==================================================== */
            $user_list .= '<li>' . $matches[1] . '</li>';
            $user_array[] = $matches[1];
        }
    }
    top_header();
    html_start_box('<strong>' . $user_actions[$_POST['drp_action']] . '</strong>', '60%', '', '3', 'center', '');
    print "<form action='mikrotik_users.php' autocomplete='off' method='post'>\n";
    if (isset($user_array) && sizeof($user_array)) {
        if ($_POST['drp_action'] == '1') {
            /* delete */
            print "\t<tr>\n\t\t\t\t\t<td class='textArea'>\n\t\t\t\t\t\t<p>When you click \"Continue\" the following Users(s) and their Graph(s) will be deleted.</p>\n\t\t\t\t\t\t<ul>" . $user_list . "</ul>";
            print "</td></tr>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\n\t\t\t\t";
            $save_html = "<input type='button' value='Cancel' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='Continue' title='Delete Device(s)'>";
        }
    } else {
        print "<tr><td><span class='textError'>You must select at least one User.</span></td></tr>\n";
        $save_html = "<input type='button' value='Return' onClick='cactiReturnTo()'>";
    }
    print "<tr class='saveRow'>\n\t\t<td colspan='2' align='right' bgcolor='#eaeaea'>\n\t\t\t<input type='hidden' name='action' value='actions'>\n\t\t\t<input type='hidden' name='selected_items' value='" . (isset($user_array) ? serialize($user_array) : '') . "'>\n\t\t\t<input type='hidden' name='drp_action' value='" . $_POST["drp_action"] . "'>\n\t\t\t{$save_html}\n\t\t</td>\n\t</tr>\n";
    html_end_box();
    bottom_footer();
}
function add_host_based_graphs()
{
    global $config;
    debug('Adding Host Based Graphs');
    /* check for host level graphs next data queries */
    $host_cpu_dq = read_config_option('mikrotik_dq_host_cpu');
    $host_users_dq = mikrotik_data_query_by_hash('ce63249e6cc3d52bc69659a3f32194fe');
    $host_users_gt = mikrotik_template_by_hash('99e37ff13139f586d257ba9a637d7340');
    $host_procs_gt = mikrotik_template_by_hash('e797d967db24fd86341a8aa8c60fa9e0');
    $host_disk_gt = mikrotik_template_by_hash('0ece13b90785aa04d1f554a093685948');
    $host_mem_gt = mikrotik_template_by_hash('4396ae857c4f9bc5ed1f26b5361e42d9');
    $host_cpu_gt = mikrotik_template_by_hash('7df474393f58bae8e8d6b85f10efad71');
    $host_arp_gt = mikrotik_template_by_hash('32bd34d525944127063c2d94e2e8f1de');
    $host_rts_gt = mikrotik_template_by_hash('8856e3943ecc70e5da835072f584d5a0');
    $host_ppp_gt = mikrotik_template_by_hash('47ced1c199d83e8dd79c6ba594c4e3be');
    $host_upt_gt = mikrotik_template_by_hash('7d8dc3050621a2cb937cac3895bc5d5b');
    $hosts = db_fetch_assoc("SELECT host_id, host.description FROM plugin_mikrotik_system\n\t\tINNER JOIN host\n\t\tON host.id=plugin_mikrotik_system.host_id\n\t\tWHERE host_status=3 AND host.disabled=''");
    if (sizeof($hosts)) {
        foreach ($hosts as $h) {
            debug("Processing Host '" . $h['description'] . '[' . $h['host_id'] . "]'");
            if ($host_users_gt) {
                debug('Processing Users');
                mikrotik_gt_graph($h['host_id'], $host_users_gt);
            } else {
                debug('Users Graph Template Not Set');
            }
            if ($host_users_gt) {
                debug('Processing Processes');
                mikrotik_gt_graph($h['host_id'], $host_procs_gt);
            } else {
                debug('Processes Graph Template Not Set');
            }
            if ($host_disk_gt) {
                debug('Processing Disk');
                mikrotik_gt_graph($h['host_id'], $host_disk_gt);
            } else {
                debug('Disk Graph Template Not Set');
            }
            if ($host_mem_gt) {
                debug('Processing Memory');
                mikrotik_gt_graph($h['host_id'], $host_mem_gt);
            } else {
                debug('Memory Graph Template Not Set');
            }
            if ($host_cpu_gt) {
                debug('Processing CPU');
                mikrotik_gt_graph($h['host_id'], $host_cpu_gt);
            } else {
                debug('CPU Graph Template Not Set');
            }
            if ($host_arp_gt) {
                debug('Processing ARP');
                mikrotik_gt_graph($h['host_id'], $host_arp_gt);
            } else {
                debug('ARP Graph Template Not Set');
            }
            if ($host_rts_gt) {
                debug('Processing Routes');
                mikrotik_gt_graph($h['host_id'], $host_rts_gt);
            } else {
                debug('Routes Graph Template Not Set');
            }
            if ($host_ppp_gt) {
                debug('Processing PPP Active');
                mikrotik_gt_graph($h['host_id'], $host_ppp_gt);
            } else {
                debug('PPP Active Graph Template Not Set');
            }
            if ($host_upt_gt) {
                debug('Processing Uptime');
                mikrotik_gt_graph($h['host_id'], $host_upt_gt);
            } else {
                debug('Uptime Graph Template Not Set');
            }
            debug('Processing Users');
            if ($host_users_dq) {
                add_host_dq_graphs($h['host_id'], $host_users_dq);
            }
            debug('Processing CPU');
            if ($host_cpu_dq) {
                add_host_dq_graphs($h['host_id'], $host_cpu_dq);
            }
        }
    } else {
        debug('No Hosts Found');
    }
}