Exemplo n.º 1
2
function collect_pppoe_users_api(&$host)
{
    $rows = array();
    $api = new RouterosAPI();
    $api->debug = false;
    $rekey_array = array('host_id', 'name', 'index', 'userType', 'serverID', 'domain', 'bytesIn', 'bytesOut', 'packetsIn', 'packetsOut', 'curBytesIn', 'curBytesOut', 'curPacketsIn', 'curPacketsOut', 'prevBytesIn', 'prevBytesOut', 'prevPacketsIn', 'prevPacketsOut', 'present', 'last_seen');
    // Put the queues into an array
    $users = array_rekey(db_fetch_assoc_prepared("SELECT \n\t\thost_id, '0' AS `index`, '1' AS userType, '0' AS serverID, SUBSTRING(name, 7) AS name, '' AS domain,\n\t\tBytesIn AS bytesIn, BytesOut AS bytesOut, PacketsIn as packetsIn, PacketsOut AS packetsOut,\n\t\tcurBytesIn, curBytesOut, curPacketsIn, curPacketsOut, \n\t\tprevBytesIn, prevBytesOut, prevPacketsIn, prevPacketsOut, present, last_seen\n\t\tFROM plugin_mikrotik_queues \n\t\tWHERE host_id = ? \n\t\tAND name LIKE 'PPPOE-%'", array($host['id'])), 'name', $rekey_array);
    $creds = db_fetch_row_prepared('SELECT * FROM plugin_mikrotik_credentials WHERE host_id = ?', array($host['id']));
    $start = microtime(true);
    if (sizeof($creds)) {
        if ($api->connect($host['hostname'], $creds['user'], $creds['password'])) {
            $api->write('/ppp/active/getall');
            $read = $api->read(false);
            $array = $api->parseResponse($read);
            $end = microtime(true);
            $sql = array();
            cacti_log('MIKROTIK RouterOS API STATS: API Returned ' . sizeof($array) . ' PPPoe Users in ' . round($end - $start, 2) . ' seconds.', false, 'SYSTEM');
            if (sizeof($array)) {
                foreach ($array as $row) {
                    if (!isset($row['name'])) {
                        continue;
                    }
                    $name = strtoupper($row['name']);
                    if (isset($users[$name])) {
                        $user = $users[$name];
                        $user['mac'] = $row['caller-id'];
                        $user['ip'] = $row['address'];
                        $user['connectTime'] = uptimeToSeconds($row['uptime']);
                        $user['host_id'] = $host['id'];
                        $user['radius'] = $row['radius'] == 'true' ? 1 : 0;
                        $user['limitBytesIn'] = $row['limit-bytes-in'];
                        $user['limitBytesOut'] = $row['limit-bytes-out'];
                        $user['userType'] = 1;
                        $sql[] = '(' . $user['host_id'] . ',' . $user['index'] . ',' . $user['userType'] . ',' . $user['serverID'] . ',' . db_qstr($user['name']) . ',' . db_qstr($user['domain']) . ',' . db_qstr($user['mac']) . ',' . db_qstr($user['ip']) . ',' . $user['connectTime'] . ',' . $user['bytesIn'] . ',' . $user['bytesOut'] . ',' . $user['packetsIn'] . ',' . $user['packetsOut'] . ',' . $user['curBytesIn'] . ',' . $user['curBytesOut'] . ',' . $user['curPacketsIn'] . ',' . $user['curPacketsOut'] . ',' . $user['prevBytesIn'] . ',' . $user['prevBytesOut'] . ',' . $user['prevPacketsIn'] . ',' . $user['prevPacketsOut'] . ',' . $user['limitBytesIn'] . ',' . $user['limitBytesOut'] . ',' . $user['radius'] . ',' . $user['present'] . ',' . db_qstr($user['last_seen']) . ')';
                    }
                }
                if (sizeof($sql)) {
                    db_execute('INSERT INTO plugin_mikrotik_users 
						(host_id, `index`, userType, serverID, name, domain, mac, ip, connectTime, 
						bytesIn, bytesOut, packetsIn, packetsOut, 
						curBytesIn, curBytesOut, curPacketsIn, curPacketsOut, 
						prevBytesIn, prevBytesOut, prevPacketsIn, prevPacketsOut, 
						limitBytesIn, limitBytesOut, radius, present, last_seen) 
						VALUES ' . implode(', ', $sql) . '
						ON DUPLICATE KEY UPDATE connectTime=VALUES(connectTime), 
						bytesIn=VALUES(bytesIn), bytesOut=VALUES(bytesOut), 
						packetsIn=VALUES(packetsIn), packetsOut=VALUES(packetsOut), 
						curBytesIn=VALUES(curBytesIn), curBytesOut=VALUES(curBytesOut),
						curPacketsIn=VALUES(curPacketsIn), curPacketsOut=VALUES(curPacketsOut),
						prevBytesIn=VALUES(prevBytesIn), prevBytesOut=VALUES(prevBytesOut),
						prevPacketsIn=VALUES(prevPacketsIn), prevPacketsOut=VALUES(prevPacketsOut),
						limitBytesIn=VALUES(limitBytesIn), limitBytesOut=VALUES(limitBytesOut),
						radius=VALUES(radius), present=VALUES(present), last_seen=VALUES(last_seen)');
                }
            }
            $idle_users = db_fetch_assoc_prepared('SELECT name 
				FROM plugin_mikrotik_users 
				WHERE last_seen < FROM_UNIXTIME(UNIX_TIMESTAMP() - ?) 
				AND present=1 
				AND host_id = ?', array(read_config_option('mikrotik_queues_freq'), $host['id']));
            db_execute_prepared('UPDATE IGNORE plugin_mikrotik_users SET
				bytesIn=0, bytesOut=0, packetsIn=0, packetsOut=0, connectTime=0,
				curBytesIn=0, curBytesOut=0, curPacketsIn=0, curPacketsOut=0,
				prevBytesIn=0, prevBytesOut=0, prevPacketsIn=0, prevPacketsOut=0, present=0
				WHERE host_id = ? 
				AND userType = 1 
				AND last_seen < FROM_UNIXTIME(UNIX_TIMESTAMP() - ?)', array($host['id'], read_config_option('mikrotik_queues_freq')));
            $api->disconnect();
        } else {
            cacti_log('ERROR:RouterOS @ ' . $host['description'] . ' Timed Out');
        }
    }
}
Exemplo n.º 2
0
function api_poller_cache_item_add($host_id, $host_field_override, $local_data_id, $rrd_step, $poller_action_id, $data_source_item_name, $num_rrd_items, $arg1 = '', $arg2 = '', $arg3 = '')
{
    static $hosts = array();
    if (!isset($hosts[$host_id])) {
        $host = db_fetch_row_prepared('SELECT
		host.id,
		host.hostname,
		host.snmp_community,
		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,
		host.disabled
		FROM host
		WHERE host.id = ?', array($host_id));
        $hosts[$host_id] = $host;
    } else {
        $host = $hosts[$host_id];
    }
    /* the $host_field_override array can be used to override certain host fields in the poller cache */
    if (isset($host)) {
        $host = array_merge($host, $host_field_override);
    }
    if (isset($host['id']) || isset($host_id)) {
        if (isset($host)) {
            if ($host['disabled'] == 'on') {
                return;
            }
        } else {
            if ($poller_action_id == 0) {
                return;
            }
            $host['id'] = 0;
            $host['snmp_community'] = '';
            $host['snmp_timeout'] = '';
            $host['snmp_username'] = '';
            $host['snmp_password'] = '';
            $host['snmp_auth_protocol'] = '';
            $host['snmp_priv_passphrase'] = '';
            $host['snmp_priv_protocol'] = '';
            $host['snmp_context'] = '';
            $host['snmp_version'] = '';
            $host['snmp_port'] = '';
            $host['hostname'] = 'None';
        }
        if ($poller_action_id == 0) {
            if ($host['snmp_version'] < 1 || $host['snmp_version'] > 3 || $host['snmp_community'] == '' && $host['snmp_version'] != 3) {
                return;
            }
        }
        $rrd_next_step = api_poller_get_rrd_next_step($rrd_step, $num_rrd_items);
        return "({$local_data_id}, " . '0, ' . $host['id'] . ", {$poller_action_id}," . db_qstr($host['hostname']) . ",\n\t\t\t" . db_qstr($host['snmp_community']) . ', ' . db_qstr($host['snmp_version']) . ', ' . db_qstr($host['snmp_timeout']) . ",\n\t\t\t" . db_qstr($host['snmp_username']) . ', ' . db_qstr($host['snmp_password']) . ', ' . db_qstr($host['snmp_auth_protocol']) . ",\n\t\t\t" . db_qstr($host['snmp_priv_passphrase']) . ', ' . db_qstr($host['snmp_priv_protocol']) . ', ' . db_qstr($host['snmp_context']) . ",\n\t\t\t" . db_qstr($host['snmp_port']) . ', ' . db_qstr($data_source_item_name) . ', ' . db_qstr(clean_up_path(get_data_source_path($local_data_id, true))) . ",\n\t\t\t" . db_qstr($num_rrd_items) . ', ' . db_qstr($rrd_step) . ', ' . db_qstr($rrd_next_step) . ', ' . db_qstr($arg1) . ', ' . db_qstr($arg2) . ', ' . db_qstr($arg3) . ", '1')";
    }
}
function get_CTAlias_table($site, &$device)
{
    global $debug, $scan_date;
    mactrack_debug("FUNCTION: get_CTAlias_table started");
    /* get the CTAlias Table for the device */
    $CTAliasInterfaces = xform_indexed_data(".1.3.6.1.4.1.52.4.1.3.7.1.1.1.1.3", $device, 2);
    mactrack_debug("CTAliasInterfaces data collection complete: " . sizeof($CTAliasInterfaces));
    /* get the CTAliasMacAddress for the device */
    $CTAliasMacAddress = xform_indexed_data(".1.3.6.1.4.1.52.4.1.3.7.1.1.1.1.4", $device, 2);
    mactrack_debug("CTAliasMacAddress data collection complete: " . sizeof($CTAliasMacAddress));
    /* convert the mac address if necessary */
    $keys = array_keys($CTAliasMacAddress);
    $i = 0;
    foreach ($CTAliasMacAddress as $MacAddress) {
        $CTAliasMacAddress[$keys[$i]] = xform_mac_address($MacAddress);
        $i++;
    }
    /* get the CTAliasProtocol Table for the device */
    $CTAliasProtocol = xform_indexed_data(".1.3.6.1.4.1.52.4.1.3.7.1.1.1.1.6", $device, 2);
    mactrack_debug("CTAliasProtocol data collection complete: " . sizeof($CTAliasProtocol));
    /* get the CTAliasAddressText for the device */
    $CTAliasAddressText = xform_indexed_data(".1.3.6.1.4.1.52.4.1.3.7.1.1.1.1.9", $device, 2);
    mactrack_debug("CTAliasAddressText data collection complete: " . sizeof($CTAliasAddressText));
    /* get the ifNames for the device */
    $keys = array_keys($CTAliasInterfaces);
    $i = 0;
    $CTAliasEntries = array();
    foreach ($CTAliasInterfaces as $ifIndex) {
        $CTAliasEntries[$i]["ifIndex"] = $ifIndex;
        #		$CTAliasEntries[$i]["timestamp"] = @substr($keys[$i], 0, stripos($keys[$i], '.'));
        $CTAliasEntries[$i]["timestamp"] = $keys[$i];
        $CTAliasEntries[$i]["CTAliasProtocol"] = @$CTAliasProtocol[$keys[$i]];
        $CTAliasEntries[$i]["CTAliasMacAddress"] = @$CTAliasMacAddress[$keys[$i]];
        #		$CTAliasEntries[$i]["CTAliasAddressText"] = @xform_net_address($CTAliasAddressText[$keys[$i]]);
        $CTAliasEntries[$i]["CTAliasAddressText"] = @$CTAliasAddressText[$keys[$i]];
        $i++;
    }
    mactrack_debug("CTAliasEntries assembly complete: " . sizeof($CTAliasEntries));
    /* output details to database */
    if (count($CTAliasEntries) > 0) {
        foreach ($CTAliasEntries as $CTAliasEntry) {
            /* drop non-IP protocols */
            if ($CTAliasEntry["CTAliasProtocol"] != 1) {
                continue;
            }
            $insert_string = "REPLACE INTO mac_track_ips " . "(site_id,device_id,hostname,device_name,port_number," . "mac_address,ip_address,scan_date)" . " VALUES ('" . $device["site_id"] . "','" . $device["device_id"] . "','" . $device["hostname"] . "'," . db_qstr($device["device_name"]) . ",'" . $CTAliasEntry["ifIndex"] . "','" . $CTAliasEntry["CTAliasMacAddress"] . "','" . $CTAliasEntry["CTAliasAddressText"] . "','" . $scan_date . "')";
            #			mactrack_debug("SQL: " . $insert_string);
            db_execute($insert_string);
        }
    }
    /* save ip information for the device */
    $device["ips_total"] = sizeof($CTAliasEntries);
    db_execute("UPDATE mac_track_devices SET ips_total ='" . $device["ips_total"] . "' WHERE device_id='" . $device["device_id"] . "'");
    mactrack_debug("HOST: " . $device["hostname"] . ", IP address information collection complete: " . $device["ips_total"]);
}
Exemplo n.º 4
0
function get_netscreen_arp_table($site, &$device)
{
    global $debug, $scan_date;
    /* get the atifIndexes for the device */
    $atifIndexes = xform_indexed_data('.1.3.6.1.2.1.3.1.1.1', $device, 6);
    if (sizeof($atifIndexes)) {
        $ifIntcount = 1;
    } else {
        $ifIntcount = 0;
    }
    if ($ifIntcount != 0) {
        $atifIndexes = xform_indexed_data('.1.3.6.1.2.1.4.22.1.1', $device, 5);
    }
    mactrack_debug(__('atifIndexes data collection complete'));
    /* get the atPhysAddress for the device */
    if ($ifIntcount != 0) {
        $atPhysAddress = xform_indexed_data('.1.3.6.1.2.1.4.22.1.2', $device, 5);
    } else {
        $atPhysAddress = xform_indexed_data('.1.3.6.1.2.1.3.1.1.2', $device, 6);
    }
    /* convert the mac address if necessary */
    $keys = array_keys($atPhysAddress);
    $i = 0;
    if (sizeof($atPhysAddress)) {
        foreach ($atPhysAddress as $atAddress) {
            $atPhysAddress[$keys[$i]] = xform_mac_address($atAddress);
            $i++;
        }
    }
    mactrack_debug(__('atPhysAddress data collection complete'));
    /* get the atPhysAddress for the device */
    if ($ifIntcount != 0) {
        $atNetAddress = xform_indexed_data('.1.3.6.1.2.1.4.22.1.3', $device, 5);
    } else {
        $atNetAddress = xform_indexed_data('.1.3.6.1.2.1.3.1.1.3', $device, 6);
    }
    mactrack_debug(__('atNetAddress data collection complete'));
    /* get the ifNames for the device */
    $keys = array_keys($atifIndexes);
    $i = 0;
    if (sizeof($atifIndexes)) {
        foreach ($atifIndexes as $atifIndex) {
            $atEntries[$i]['atifIndex'] = $atifIndex;
            $atEntries[$i]['atPhysAddress'] = $atPhysAddress[$keys[$i]];
            $atEntries[$i]['atNetAddress'] = xform_net_address($atNetAddress[$keys[$i]]);
            $i++;
        }
    }
    mactrack_debug(__('atEntries assembly complete.'));
    /* output details to database */
    if (sizeof($atEntries)) {
        foreach ($atEntries as $atEntry) {
            $insert_string = 'REPLACE INTO mac_track_ips 
				(site_id,device_id,hostname,device_name,port_number,
				mac_address,ip_address,scan_date)
				 VALUES (' . $device['site_id'] . ',' . $device['device_id'] . ',' . db_qstr($device['hostname']) . ',' . db_qstr($device['device_name']) . ',' . db_qstr($atEntry['atifIndex']) . ',' . db_qstr($atEntry['atPhysAddress']) . ',' . db_qstr($atEntry['atNetAddress']) . ',' . db_qstr($scan_date) . ')';
            db_execute($insert_string);
        }
    }
    /* save ip information for the device */
    $device['ips_total'] = sizeof($atEntries);
    db_execute('UPDATE mac_track_devices SET ips_total =' . $device['ips_total'] . ' WHERE device_id=' . $device['device_id']);
    mactrack_debug(__('HOST: %s, IP address information collection complete', $device['hostname']));
}
Exemplo n.º 5
0
function data_query_format_record($host_id, $snmp_query_id, $field_name, $value, $snmp_index, $oid)
{
    return "({$host_id}, {$snmp_query_id}, " . db_qstr($field_name) . ", " . db_qstr($value) . ", " . db_qstr($snmp_index) . ", " . db_qstr($oid) . ", 1)";
}
Exemplo n.º 6
0
function template_save_edit()
{
    /* ================= input validation ================= */
    get_filter_request_var('id');
    get_filter_request_var('thold_type');
    get_filter_request_var('thold_hi');
    get_filter_request_var('thold_low');
    get_filter_request_var('thold_fail_trigger');
    get_filter_request_var('time_hi');
    get_filter_request_var('time_low');
    get_filter_request_var('time_fail_trigger');
    get_filter_request_var('time_fail_length');
    get_filter_request_var('thold_warning_type');
    get_filter_request_var('thold_warning_hi');
    get_filter_request_var('thold_warning_low');
    get_filter_request_var('thold_warning_fail_trigger');
    get_filter_request_var('time_warning_hi');
    get_filter_request_var('time_warning_low');
    get_filter_request_var('time_warning_fail_trigger');
    get_filter_request_var('time_warning_fail_length');
    get_filter_request_var('bl_ref_time_range');
    get_filter_request_var('bl_pct_down');
    get_filter_request_var('bl_pct_up');
    get_filter_request_var('bl_fail_trigger');
    get_filter_request_var('repeat_alert');
    get_filter_request_var('data_type');
    get_filter_request_var('cdef');
    get_filter_request_var('notify_warning');
    get_filter_request_var('notify_alert');
    get_filter_request_var('snmp_event_severity');
    get_filter_request_var('snmp_event_warning_severity');
    /* ==================================================== */
    /* clean up date1 string */
    if (isset_request_var('name')) {
        set_request_var('name', trim(str_replace(array("\\", "'", '"'), '', get_nfilter_request_var('name'))));
    }
    if (isset_request_var('snmp_trap_category')) {
        set_request_var('snmp_event_category', db_qstr(trim(str_replace(array("\\", "'", '"'), '', get_nfilter_request_var('snmp_event_category')))));
    }
    /* save: data_template */
    $save['id'] = get_nfilter_request_var('id');
    $save['hash'] = get_hash_thold_template($save['id']);
    $save['name'] = get_nfilter_request_var('name');
    $save['thold_type'] = get_nfilter_request_var('thold_type');
    // High / Low
    $save['thold_hi'] = get_nfilter_request_var('thold_hi');
    $save['thold_low'] = get_nfilter_request_var('thold_low');
    $save['thold_fail_trigger'] = get_nfilter_request_var('thold_fail_trigger');
    // Time Based
    $save['time_hi'] = get_nfilter_request_var('time_hi');
    $save['time_low'] = get_nfilter_request_var('time_low');
    $save['time_fail_trigger'] = get_nfilter_request_var('time_fail_trigger');
    $save['time_fail_length'] = get_nfilter_request_var('time_fail_length');
    if (isset_request_var('thold_fail_trigger') && get_nfilter_request_var('thold_fail_trigger') != '') {
        $save['thold_fail_trigger'] = get_nfilter_request_var('thold_fail_trigger');
    } else {
        $alert_trigger = read_config_option('alert_trigger');
        if ($alert_trigger != '' && is_numeric($alert_trigger)) {
            $save['thold_fail_trigger'] = $alert_trigger;
        } else {
            $save['thold_fail_trigger'] = 5;
        }
    }
    /***  Warnings  ***/
    // High / Low Warnings
    $save['thold_warning_hi'] = get_nfilter_request_var('thold_warning_hi');
    $save['thold_warning_low'] = get_nfilter_request_var('thold_warning_low');
    $save['thold_warning_fail_trigger'] = get_nfilter_request_var('thold_warning_fail_trigger');
    // Time Based Warnings
    $save['time_warning_hi'] = get_nfilter_request_var('time_warning_hi');
    $save['time_warning_low'] = get_nfilter_request_var('time_warning_low');
    $save['time_warning_fail_trigger'] = get_nfilter_request_var('time_warning_fail_trigger');
    $save['time_warning_fail_length'] = get_nfilter_request_var('time_warning_fail_length');
    if (isset_request_var('thold_warning_fail_trigger') && get_nfilter_request_var('thold_warning_fail_trigger') != '') {
        $save['thold_warning_fail_trigger'] = get_nfilter_request_var('thold_warning_fail_trigger');
    } else {
        $alert_trigger = read_config_option('alert_trigger');
        if ($alert_trigger != '' && is_numeric($alert_trigger)) {
            $save['thold_warning_fail_trigger'] = $alert_trigger;
        } else {
            $save['thold_warning_fail_trigger'] = 5;
        }
    }
    $save['thold_enabled'] = isset_request_var('thold_enabled') ? 'on' : 'off';
    $save['exempt'] = isset_request_var('exempt') ? 'on' : '';
    $save['restored_alert'] = isset_request_var('restored_alert') ? 'on' : '';
    if (isset_request_var('bl_ref_time_range') && get_nfilter_request_var('bl_ref_time_range') != '') {
        $save['bl_ref_time_range'] = get_nfilter_request_var('bl_ref_time_range');
    } else {
        $alert_bl_timerange_def = read_config_option('alert_bl_timerange_def');
        if ($alert_bl_timerange_def != '' && is_numeric($alert_bl_timerange_def)) {
            $save['bl_ref_time_range'] = $alert_bl_timerange_def;
        } else {
            $save['bl_ref_time_range'] = 10800;
        }
    }
    $save['bl_pct_down'] = get_nfilter_request_var('bl_pct_down');
    $save['bl_pct_up'] = get_nfilter_request_var('bl_pct_up');
    if (isset_request_var('bl_fail_trigger') && get_nfilter_request_var('bl_fail_trigger') != '') {
        $save['bl_fail_trigger'] = get_nfilter_request_var('bl_fail_trigger');
    } else {
        $alert_bl_trigger = read_config_option('alert_bl_trigger');
        if ($alert_bl_trigger != '' && is_numeric($alert_bl_trigger)) {
            $save['bl_fail_trigger'] = $alert_bl_trigger;
        } else {
            $save['bl_fail_trigger'] = 3;
        }
    }
    if (isset_request_var('repeat_alert') && get_nfilter_request_var('repeat_alert') != '') {
        $save['repeat_alert'] = get_nfilter_request_var('repeat_alert');
    } else {
        $alert_repeat = read_config_option('alert_repeat');
        if ($alert_repeat != '' && is_numeric($alert_repeat)) {
            $save['repeat_alert'] = $alert_repeat;
        } else {
            $save['repeat_alert'] = 12;
        }
    }
    if (isset_request_var('snmp_event_category')) {
        $save['snmp_event_category'] = get_nfilter_request_var('snmp_event_category');
        $save['snmp_event_severity'] = get_nfilter_request_var('snmp_event_severity');
    }
    if (isset_request_var('snmp_event_warning_severity')) {
        if (get_nfilter_request_var('snmp_event_warning_severity') > get_nfilter_request_var('snmp_event_severity')) {
            $save['snmp_event_warning_severity'] = get_nfilter_request_var('snmp_event_severity');
        } else {
            $save['snmp_event_warning_severity'] = get_nfilter_request_var('snmp_event_warning_severity');
        }
    }
    $save['notify_extra'] = get_nfilter_request_var('notify_extra');
    $save['notify_warning_extra'] = get_nfilter_request_var('notify_warning_extra');
    $save['notify_warning'] = get_nfilter_request_var('notify_warning');
    $save['notify_alert'] = get_nfilter_request_var('notify_alert');
    $save['cdef'] = get_nfilter_request_var('cdef');
    $save['data_type'] = get_nfilter_request_var('data_type');
    $save['percent_ds'] = get_nfilter_request_var('percent_ds');
    $save['expression'] = get_nfilter_request_var('expression');
    if (!is_error_message()) {
        $id = sql_save($save, 'thold_template');
        if ($id) {
            raise_message(1);
            if (isset_request_var('notify_accounts') && is_array(get_nfilter_request_var('notify_accounts'))) {
                thold_save_template_contacts($id, get_nfilter_request_var('notify_accounts'));
            } elseif (!isset_request_var('notify_accounts')) {
                thold_save_template_contacts($id, array());
            }
            thold_template_update_thresholds($id);
            plugin_thold_log_changes($id, 'modified_template', $save);
        } else {
            raise_message(2);
        }
    }
    if (is_error_message() || isempty_request_var('id')) {
        header('Location: thold_templates.php?header=false&action=edit&id=' . (empty($id) ? get_request_var('id') : $id));
    } else {
        header('Location: thold_templates.php?header=false');
    }
}
function mactrack_rescan_device_types()
{
    global $cnn_id;
    /* let's allocate an array for results */
    $insert_array = array();
    /* get all the various device types from the database */
    $device_types = db_fetch_assoc("SELECT DISTINCT snmp_sysObjectID, snmp_sysDescr, device_type_id\n\t\tFROM mac_track_devices\n\t\tWHERE snmp_sysObjectID!='' AND snmp_sysDescr!=''");
    /* get all known devices types from the device type database */
    $known_types = db_fetch_assoc('SELECT sysDescr_match, sysObjectID_match FROM mac_track_device_types');
    /* loop through all device rows and look for a matching type */
    if (sizeof($device_types)) {
        foreach ($device_types as $type) {
            $found = FALSE;
            if (sizeof($known_types)) {
                foreach ($known_types as $known) {
                    if (substr_count($type['snmp_sysDescr'], $known['sysDescr_match']) && substr_count($type['snmp_sysObjectID'], $known['sysObjectID_match'])) {
                        $found = TRUE;
                        break;
                    }
                }
            }
            if (!$found) {
                $insert_array[] = $type;
            }
        }
    }
    if (sizeof($insert_array)) {
        foreach ($insert_array as $item) {
            $desc = trim($item['snmp_sysDescr']);
            $name = __('New Type');
            if (substr_count(strtolower($desc), 'cisco')) {
                $vendor = __('Cisco');
                $temp_name = str_replace('(tm)', '', $desc);
                $pos = strpos($temp_name, '(');
                if ($pos > 0) {
                    $pos2 = strpos($temp_name, ')');
                    if ($pos2 > $pos) {
                        $desc = substr($temp_name, $pos + 1, $pos2 - $pos - 1);
                        $name = $desc . ' (' . $item['device_type_id'] . ')';
                    }
                }
            } else {
                $vendor = __('Unknown');
            }
            db_execute("REPLACE INTO mac_track_device_types\n\t\t\t\t(description, vendor, device_type, sysDescr_match, sysObjectID_match)\n\t\t\t\tVALUES (" . db_qstr($name) . "," . db_qstr($vendor) . "," . db_qstr($item['device_type']) . "," . db_qstr($desc) . "," . db_qstr($item['snmp_sysObjectID']) . ")");
        }
        print __('There were %d Device Types Added!', sizeof($insert_array));
    } else {
        print __('No New Device Types Found!');
    }
}
Exemplo n.º 8
0
function collectHostIndexedOid(&$host, $tree, $table, $name, $preserve = false)
{
    global $cnn_id;
    static $types;
    debug("Beginning Processing for '" . $host['description'] . '[' . $host['hostname'] . "]', Table '{$name}'");
    if (sizeof($host)) {
        /* mark for deletion */
        db_execute("UPDATE {$table} SET present=0 WHERE host_id=" . $host['id']);
        debug("Polling {$name} from '" . $host['description'] . '[' . $host['hostname'] . "]'");
        $hostMib = array();
        foreach ($tree as $mname => $oid) {
            if ($name == 'processor') {
                $retrieval = SNMP_VALUE_PLAIN;
            } elseif ($mname == 'mac') {
                $retrieval = SNMP_VALUE_LIBRARY;
            } elseif ($mname == 'date') {
                $retrieval = SNMP_VALUE_LIBRARY;
            } elseif ($mname != 'baseOID') {
                $retrieval = SNMP_VALUE_PLAIN;
            } else {
                continue;
            }
            $walk = cacti_snmp_walk($host['hostname'], $host['snmp_community'], $oid, $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'), $host['max_oids'], $retrieval, SNMP_WEBUI);
            if (($mname == 'index' || $mname == 'name') && !sizeof($walk)) {
                debug('No Index Information for OID: ' . $oid . ' on ' . $host['description'] . ' returning');
                return;
            }
            $hostMib = array_merge($hostMib, $walk);
            debug('Polled: ' . $host['description'] . ', OID: ' . $oid . ', Size: ' . sizeof($walk));
        }
        $set_string = '';
        $values = '';
        $sql_suffix = '';
        $sql_prefix = "INSERT INTO {$table}";
        if (sizeof($tree)) {
            foreach ($tree as $bname => $oid) {
                if ($bname != 'baseOID' && $bname != 'index') {
                    $values .= (strlen($values) ? '`, `' : '`') . $bname;
                    $sql_suffix .= (!strlen($sql_suffix) ? ' ON DUPLICATE KEY UPDATE `index`=VALUES(`index`), `' : ', `') . $bname . '`=VALUES(`' . $bname . '`)';
                }
            }
        }
        $sql_prefix .= ' (`host_id`, `index`, ' . ($preserve ? '`last_seen`, ' : '') . $values . '`) VALUES ';
        $sql_suffix .= ', present=1' . ($preserve ? ', last_seen=NOW()' : '');
        // Locate the values names
        $prevIndex = '';
        $new_array = array();
        if (sizeof($hostMib)) {
            foreach ($hostMib as $mib) {
                /* do some cleanup */
                if (substr($mib['oid'], 0, 1) != '.') {
                    $mib['oid'] = '.' . $mib['oid'];
                }
                if (substr($mib['value'], 0, 4) == 'OID:') {
                    $mib['value'] = trim(str_replace('OID:', '', $mib['value']));
                }
                $splitIndex = mikrotik_splitBaseIndex($mib['oid']);
                if (sizeof($splitIndex)) {
                    $index = $splitIndex[1];
                    $oid = $splitIndex[0];
                    $key = array_search($oid, $tree);
                    if (!empty($key)) {
                        if ($key == 'type') {
                            if ($mib['value'] == '.1.3.6.1.2.1.25.2.1.1') {
                                $new_array[$index][$key] = 11;
                            } elseif ($mib['value'] == '.1.3.6.1.2.1.25.2.1.4') {
                                $new_array[$index][$key] = 14;
                            }
                        } elseif ($key == 'name') {
                            $new_array[$index][$key] = strtoupper($mib['value']);
                        } elseif ($key == 'date') {
                            $new_array[$index][$key] = mikrotik_dateParse($mib['value']);
                        } elseif ($key != 'index') {
                            $new_array[$index][$key] = $mib['value'];
                        }
                    }
                    if (!empty($key) && $key != 'index') {
                        debug("Key:'" . $key . "', Orig:'" . $mib['oid'] . "', Val:'" . $new_array[$index][$key] . "', Index:'" . $index . "', Base:'" . $oid . "'");
                    }
                } else {
                    echo "WARNING: Error parsing OID value\n";
                }
            }
        }
        /* dump the output to the database */
        $sql_insert = '';
        $count = 0;
        if (sizeof($new_array)) {
            foreach ($new_array as $index => $item) {
                $sql_insert .= (strlen($sql_insert) ? '), (' : '(') . $host['id'] . ', ' . $index . ', ' . ($preserve ? 'NOW(), ' : '');
                $i = 0;
                foreach ($tree as $mname => $oid) {
                    if ($mname != 'baseOID' && $mname != 'index') {
                        $sql_insert .= ($i > 0 ? ', ' : '') . (isset($item[$mname]) && strlen(strlen($item[$mname])) ? db_qstr($item[$mname]) : "''");
                        $i++;
                    }
                }
            }
            $sql_insert .= ')';
            $count++;
            if ($count % 200 == 0) {
                db_execute($sql_prefix . $sql_insert . $sql_suffix);
                $sql_insert = '';
            }
        }
        //print $sql_prefix . $sql_insert . $sql_suffix . "\n";
        if (strlen($sql_insert)) {
            db_execute($sql_prefix . $sql_insert . $sql_suffix);
        }
    }
}
Exemplo n.º 9
0
                $dns_hostname == $unresolved_ip['ip_address'];
            }
            if ($primary_down && $secondary_down) {
                mactrack_debug('ERROR: Both Primary and Seconary DNS timed out, please increase timeout. Placing both DNS servers back online now.');
                $secondary_down = FALSE;
                $primary_down = FALSE;
            }
            $unresolved_ips[$key]['dns_hostname'] = $dns_hostname;
        }
        mactrack_debug('DNS host association complete.');
        /* output updated details to database */
        foreach ($unresolved_ips as $unresolved_ip) {
            $insert_string = 'REPLACE INTO mac_track_temp_ports 
				(site_id,device_id,hostname,dns_hostname,device_name,vlan_id,vlan_name,
				mac_address,vendor_mac,ip_address,port_number,port_name,scan_date)
				VALUES (' . $unresolved_ip['site_id'] . ',' . $unresolved_ip['device_id'] . ',' . db_qstr($unresolved_ip['hostname']) . ',' . db_qstr($unresolved_ip['dns_hostname']) . ',' . db_qstr($unresolved_ip['device_name']) . ',' . $unresolved_ip['vlan_id'] . ',' . db_qstr($unresolved_ip['vlan_name']) . ',' . db_qstr($unresolved_ip['mac_address']) . ',' . db_qstr($unresolved_ip['vendor_mac']) . ',' . db_qstr($unresolved_ip['ip_address']) . ',' . db_qstr($unresolved_ip['port_number']) . ',' . db_qstr($unresolved_ip['port_name']) . ',' . db_qstr($unresolved_ip['scan_date']) . ')';
            db_execute($insert_string);
        }
        mactrack_debug('Records updated with DNS information included.');
    }
    if ($break) {
        break;
    }
}
/* allow parent to close by removing process and then exit */
db_process_remove(0);
exit;
/*	display_help - displays the usage of the function */
function display_help()
{
    $info = plugin_mactrack_version();
Exemplo n.º 10
0
function syslog_log_alert($alert_id, $alert_name, $severity, $msg, $count = 1, $html)
{
    global $config, $severities;
    include dirname(__FILE__) . '/config.php';
    if ($count <= 1) {
        $save['seq'] = '';
        $save['alert_id'] = $alert_id;
        $save['logseq'] = $msg['seq'];
        $save['logtime'] = $msg['date'] . ' ' . $msg['time'];
        $save['logmsg'] = db_qstr($msg['message']);
        $save['host'] = $msg['host'];
        $save['facility_id'] = $msg['facility_id'];
        $save['priority_id'] = $msg['priority_id'];
        $save['count'] = 1;
        $save['html'] = db_qstr($html);
        $id = 0;
        $id = syslog_sql_save($save, '`' . $syslogdb_default . '`.`syslog_logs`', 'seq');
        cacti_log("WARNING: The Syslog Alert '{$alert_name}' with Severity '" . $severities[$severity] . "', has been Triggered on Host '" . $msg['host'] . "', and Sequence '{$id}'", false, 'SYSLOG');
        return $id;
    } else {
        $save['seq'] = '';
        $save['alert_id'] = $alert_id;
        $save['logseq'] = 0;
        $save['logtime'] = date('Y-m-d H:i:s');
        $save['logmsg'] = db_qstr($alert_name);
        $save['host'] = 'N/A';
        $save['facility_id'] = $msg['facility_id'];
        $save['priority_id'] = $msg['priority_id'];
        $save['count'] = $count;
        $save['html'] = db_qstr($html);
        $id = 0;
        $id = syslog_sql_save($save, '`' . $syslogdb_default . '`.`syslog_logs`', 'seq');
        cacti_log("WARNING: The Syslog Intance Alert '{$alert_name}' with Severity '" . $severities[$severity] . "', has been Triggered, Count was '" . $count . "', and Sequence '{$id}'", false, 'SYSLOG');
        return $id;
    }
}
Exemplo n.º 11
0
$socket_int_value = $parms[0];
array_shift($parms);
/* last, recombine the arguments */
$command = implode(' ', $parms);
/* execute the command */
if ($config['cacti_server_os'] == 'win32') {
    $handle = popen($command, 'rb');
} else {
    $handle = popen($command, 'r');
}
/* get the results */
$result = fread($handle, 1024);
if (!strlen(trim($result))) {
    $result = 'OK';
} else {
    if (substr_count($result, "\r")) {
        $result = str_replace("\r", '', $result);
    }
    $result_array = explode("\n", $result);
    if (sizeof($result_array)) {
        $result = $result_array[sizeof($result_array) - 2];
    } else {
        $result = 'ERROR: Detected unknown error';
    }
}
/* add the value to the table */
db_execute("INSERT INTO poller_output_boost_processes\n\t(sock_int_value, status)\n\tVALUES ('" . $socket_int_value . "'," . db_qstr($result, get_magic_quotes_gpc()) . ')');
/* close the connection */
pclose($handle);
/* return the rrdupdate results */
return $result;
Exemplo n.º 12
0
function collectHostIndexedOid(&$host, $tree, $table, $name)
{
    global $cnn_id;
    static $types;
    debug("Beginning Processing for '" . $host['description'] . '[' . $host['hostname'] . "]', Table '{$name}'");
    if (!sizeof($types)) {
        $types = array_rekey(db_fetch_assoc('SELECT id, oid, description FROM plugin_hmib_types'), 'oid', array('id', 'description'));
    }
    $cols = db_get_table_column_types($table);
    if (sizeof($host)) {
        /* mark for deletion */
        db_execute("UPDATE {$table} SET present=0 WHERE host_id=" . $host['id']);
        debug("Polling {$name} from '" . $host['description'] . '[' . $host['hostname'] . "]'");
        $hostMib = array();
        foreach ($tree as $mname => $oid) {
            if ($name == 'hrProcessor') {
                $retrieval = SNMP_VALUE_PLAIN;
            } elseif ($mname == 'date') {
                $retrieval = SNMP_VALUE_LIBRARY;
            } elseif ($mname != 'baseOID') {
                $retrieval = SNMP_VALUE_PLAIN;
            } else {
                continue;
            }
            $walk = cacti_snmp_walk($host['hostname'], $host['snmp_community'], $oid, $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'), $host['max_oids'], $retrieval, SNMP_WEBUI);
            $hostMib = array_merge($hostMib, $walk);
        }
        $set_string = '';
        $values = '';
        $sql_suffix = '';
        $sql_prefix = "INSERT INTO {$table}";
        if (sizeof($tree)) {
            foreach ($tree as $bname => $oid) {
                if ($bname != 'baseOID' && $bname != 'index') {
                    $values .= (strlen($values) ? '`, `' : '`') . $bname;
                    $sql_suffix .= (!strlen($sql_suffix) ? ' ON DUPLICATE KEY UPDATE `index`=VALUES(`index`), `' : ', `') . $bname . '`=VALUES(`' . $bname . '`)';
                }
            }
        }
        $sql_prefix .= ' (`host_id`, `index`, ' . $values . '`) VALUES ';
        $sql_suffix .= ', present=1';
        // Locate the values names
        $prevIndex = '';
        $new_array = array();
        $wonky = false;
        $hrProcValid = false;
        $effective = 0;
        if (sizeof($hostMib)) {
            foreach ($hostMib as $mib) {
                /* do some cleanup */
                if (substr($mib['oid'], 0, 1) != '.') {
                    $mib['oid'] = '.' . $mib['oid'];
                }
                if (substr($mib['value'], 0, 4) == 'OID:') {
                    $mib['value'] = trim(str_replace('OID:', '', $mib['value']));
                }
                $splitIndex = hmib_splitBaseIndex($mib['oid']);
                if (sizeof($splitIndex)) {
                    $index = $splitIndex[1];
                    $oid = $splitIndex[0];
                    $key = array_search($oid, $tree);
                    /* issue workaround for snmp issues */
                    if ($name == 'hrProcessor' && $mib['value'] == '.0.0') {
                        if ($wonky) {
                            $key = 'load';
                            $mib['value'] = $effective;
                        } elseif (!$hrProcValid) {
                            if (db_fetch_cell("SELECT count(*) FROM plugin_hmib_hrSystem WHERE sysDescr LIKE '%Linux%' AND host_id=" . $host['id'])) {
                                /* look for the hrProcessorLoad value */
                                $temp_mib = $hostMib;
                                foreach ($temp_mib as $kk => $vv) {
                                    if (substr_count($kk, '.1.3.6.1.2.1.25.3.3.1.2')) {
                                        $hrProcValid = true;
                                    }
                                }
                                if (!$hrProcValid) {
                                    $user = cacti_snmp_get($host['hostname'], $host['snmp_community'], '.1.3.6.1.4.1.2021.11.9.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'), $host['max_oids'], SNMP_VALUE_LIBRARY, SNMP_WEBUI);
                                    $system = cacti_snmp_get($host['hostname'], $host['snmp_community'], '.1.3.6.1.4.1.2021.11.10.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'), $host['max_oids'], SNMP_VALUE_LIBRARY, SNMP_WEBUI);
                                    $effective = ($user + $system) * 2 / sizeof($mib);
                                    $key = 'load';
                                    $mib['value'] = $effective;
                                    $wonky = true;
                                }
                            } else {
                                $effective = 0;
                            }
                        }
                    }
                    if (!empty($key)) {
                        if ($key == 'type') {
                            $value = explode('(', $mib['value']);
                            if (sizeof($value) > 1) {
                                $value = trim($value[1], " \n\r)");
                                if ($table != 'plugin_hmib_hrSWInstalled' && $table != 'plugin_hmib_hrSWRun') {
                                    $new_array[$index][$key] = isset($types[$value]) ? $types[$value]['id'] : 0;
                                } else {
                                    $new_array[$index][$key] = $value;
                                }
                            } else {
                                if ($table != 'plugin_hmib_hrSWInstalled' && $table != 'plugin_hmib_hrSWRun') {
                                    $new_array[$index][$key] = isset($types[$value[0]]) ? $types[$value[0]]['id'] : 0;
                                } else {
                                    $new_array[$index][$key] = $value[0];
                                }
                            }
                        } elseif ($key == 'date') {
                            $new_array[$index][$key] = hmib_dateParse($mib['value']);
                        } elseif ($key == 'name' && $table == 'plugin_hmib_hrSWRun') {
                            if (!empty($mib['value']) && $mib['value'] != 'NULL') {
                                $parts = explode('/', $mib['value']);
                                $new_array[$index][$key] = $parts[0];
                            } else {
                                $new_array[$index][$key] = '';
                            }
                        } elseif ($key == 'path' && $table == 'plugin_hmib_hrSWRun') {
                            if (!empty($mib['value']) && $mib['value'] != 'NULL') {
                                $new_array[$index][$key] = $mib['value'];
                            } else {
                                $new_array[$index][$key] = '';
                            }
                        } elseif ($key == 'parameters' && $table == 'plugin_hmib_hrSWRun') {
                            if (!empty($mib['value']) && $mib['value'] != 'NULL') {
                                $new_array[$index][$key] = $mib['value'];
                            } else {
                                $new_array[$index][$key] = '';
                            }
                        } elseif ($key != 'index') {
                            if (isset($cols[$key]['type'])) {
                                if (strstr($cols[$key]['type'], 'int') !== false || strstr($cols[$key]['type'], 'float') !== false || strstr($cols[$key]['type'], 'double') !== false) {
                                    if (empty($mib['value'])) {
                                        $new_array[$index][$key] = 0;
                                    } else {
                                        $new_array[$index][$key] = $mib['value'];
                                    }
                                } else {
                                    $new_array[$index][$key] = $mib['value'];
                                }
                            } else {
                                $new_array[$index][$key] = $mib['value'];
                            }
                        }
                    }
                    if (!empty($key) && $key != 'index') {
                        debug("Key:'" . $key . "', Orig:'" . $mib['oid'] . "', Val:'" . $new_array[$index][$key] . "', Index:'" . $index . "', Base:'" . $oid . "'");
                    }
                } else {
                    echo "WARNING: Error parsing OID value\n";
                }
            }
        }
        /* dump the output to the database */
        $sql_insert = '';
        $count = 0;
        if (sizeof($new_array)) {
            foreach ($new_array as $index => $item) {
                $sql_insert .= (strlen($sql_insert) ? '), (' : '(') . $host['id'] . ', ' . $index . ', ';
                $i = 0;
                foreach ($tree as $key => $oid) {
                    if ($key != 'baseOID' && $key != 'index') {
                        if (isset($item[$key]) && strlen(strlen($item[$key]))) {
                            if (isset($cols[$key]['type'])) {
                                if (strstr($cols[$key]['type'], 'int') !== false || strstr($cols[$key]['type'], 'float') !== false || strstr($cols[$key]['type'], 'double') !== false) {
                                    $sql_insert .= ($i > 0 ? ', ' : '') . (isset($item[$key]) ? $item[$key] : 0);
                                } else {
                                    $sql_insert .= ($i > 0 ? ', ' : '') . (isset($item[$key]) ? db_qstr($item[$key]) : '""');
                                }
                                $i++;
                            }
                        } else {
                            if (isset($cols[$key])) {
                                if (strstr($cols[$key]['type'], 'int') !== false || strstr($cols[$key]['type'], 'float') !== false || strstr($cols[$key]['type'], 'double') !== false) {
                                    $sql_insert .= ($i > 0 ? ', ' : '') . (isset($item[$key]) ? $item[$key] : 0);
                                } else {
                                    $sql_insert .= ($i > 0 ? ', ' : '') . (isset($item[$key]) ? db_qstr($item[$key]) : '""');
                                }
                                $i++;
                            }
                        }
                    }
                }
            }
            $sql_insert .= ')';
            $count++;
            if ($count % 200 == 0) {
                db_execute($sql_prefix . $sql_insert . $sql_suffix);
                $sql_insert = '';
            }
        }
        if ($sql_insert != '') {
            db_execute($sql_prefix . $sql_insert . $sql_suffix);
        }
        /* remove old records */
        db_execute("DELETE FROM {$table} WHERE present=0 AND host_id=" . $host['id']);
    }
}
Exemplo n.º 13
0
function hmib_host_type_import_processor(&$host_types)
{
    $i = 0;
    $sysDescrMatch_id = -1;
    $sysObjectID_id = -1;
    $host_type_id = -1;
    $save_vendor_id = -1;
    $save_description_id = -1;
    $save_version_id = -1;
    $save_name_id = -1;
    $save_order = '';
    $update_suffix = '';
    $return_array = array();
    $insert_columns = array();
    foreach ($host_types as $host_type) {
        /* parse line */
        $line_array = str_getcsv($host_type);
        //$line_array = explode(',', $host_type);
        /* header row */
        if ($i == 0) {
            $save_order = '(';
            $j = 0;
            $first_column = TRUE;
            $update_suffix = '';
            $required = 0;
            foreach ($line_array as $line_item) {
                switch ($line_item) {
                    case 'id':
                        if (!$first_column) {
                            $save_order .= ', ';
                        }
                        $host_type_id = $j;
                        $required++;
                        $save_order .= $line_item;
                        $insert_columns[] = $j;
                        $first_column = FALSE;
                        if (strlen($update_suffix)) {
                            $update_suffix .= ", {$line_item}=VALUES({$line_item})";
                        } else {
                            $update_suffix .= " ON DUPLICATE KEY UPDATE {$line_item}=VALUES({$line_item})";
                        }
                        break;
                    case 'sysDescrMatch':
                        if (!$first_column) {
                            $save_order .= ', ';
                        }
                        $sysDescrMatch_id = $j;
                        $required++;
                        $save_order .= $line_item;
                        $insert_columns[] = $j;
                        $first_column = FALSE;
                        if (strlen($update_suffix)) {
                            $update_suffix .= ", {$line_item}=VALUES({$line_item})";
                        } else {
                            $update_suffix .= " ON DUPLICATE KEY UPDATE {$line_item}=VALUES({$line_item})";
                        }
                        break;
                    case 'sysObjectID':
                        if (!$first_column) {
                            $save_order .= ', ';
                        }
                        $sysObjectID_id = $j;
                        $required++;
                        $save_order .= $line_item;
                        $insert_columns[] = $j;
                        $first_column = FALSE;
                        if (strlen($update_suffix)) {
                            $update_suffix .= ", {$line_item}=VALUES({$line_item})";
                        } else {
                            $update_suffix .= " ON DUPLICATE KEY UPDATE {$line_item}=VALUES({$line_item})";
                        }
                        break;
                    case 'version':
                        if (!$first_column) {
                            $save_order .= ', ';
                        }
                        $save_order .= $line_item;
                        $insert_columns[] = $j;
                        $save_vendor_id = $j;
                        $first_column = FALSE;
                        if (strlen($update_suffix)) {
                            $update_suffix .= ", {$line_item}=VALUES({$line_item})";
                        } else {
                            $update_suffix .= " ON DUPLICATE KEY UPDATE {$line_item}=VALUES({$line_item})";
                        }
                        break;
                    case 'name':
                        if (!$first_column) {
                            $save_order .= ', ';
                        }
                        $save_order .= $line_item;
                        $insert_columns[] = $j;
                        $save_description_id = $j;
                        $first_column = FALSE;
                        if (strlen($update_suffix)) {
                            $update_suffix .= ", {$line_item}=VALUES({$line_item})";
                        } else {
                            $update_suffix .= " ON DUPLICATE KEY UPDATE {$line_item}=VALUES({$line_item})";
                        }
                        break;
                    default:
                        /* ignore unknown columns */
                }
                $j++;
            }
            $save_order .= ')';
            if ($required >= 3) {
                array_push($return_array, '<strong>HEADER LINE PROCESSED OK</strong>:  <br>Columns found where: ' . $save_order . '<br>');
            } else {
                array_push($return_array, '<strong>HEADER LINE PROCESSING ERROR</strong>: Missing required field <br>Columns found where:' . $save_order . '<br>');
                break;
            }
        } else {
            $save_value = '(';
            $j = 0;
            $first_column = TRUE;
            $sql_where = '';
            foreach ($line_array as $line_item) {
                if (in_array($j, $insert_columns)) {
                    if (!$first_column) {
                        $save_value .= ',';
                    } else {
                        $first_column = FALSE;
                    }
                    if ($j == $host_type_id || $j == $sysDescrMatch_id || $j == $sysObjectID_id) {
                        if (strlen($sql_where)) {
                            switch ($j) {
                                case $host_type_id:
                                    $sql_where .= " AND id=" . db_qstr($line_item);
                                    break;
                                case $sysDescrMatch_id:
                                    $sql_where .= " AND sysDescrMatch=" . db_qstr($line_item);
                                    break;
                                case $sysObjectID_id:
                                    $sql_where .= " AND sysObjectID=" . db_qstr($line_item);
                                    break;
                                default:
                                    /* do nothing */
                            }
                        } else {
                            switch ($j) {
                                case $host_type_id:
                                    $sql_where .= "WHERE id=" . db_qstr($line_item);
                                    break;
                                case $sysDescrMatch_id:
                                    $sql_where .= "WHERE sysDescrMatch=" . db_qstr($line_item);
                                    break;
                                case $sysObjectID_id:
                                    $sql_where .= "WHERE sysObjectID=" . db_qstr($line_item);
                                    break;
                                default:
                                    /* do nothing */
                            }
                        }
                    }
                    if ($j == $sysDescrMatch_id) {
                        $sysDescrMatch = $line_item;
                    }
                    if ($j == $sysObjectID_id) {
                        $sysObjectID = $line_item;
                    }
                    if ($j == $save_vendor_id) {
                        $vendor = $line_item;
                    }
                    if ($j == $save_description_id) {
                        $description = $line_item;
                    }
                    $save_value .= db_qstr($line_item);
                }
                $j++;
            }
            $save_value .= ')';
            if ($j > 0) {
                if (isset_request_var('allow_update')) {
                    $sql_execute = 'INSERT INTO mac_track_device_types ' . $save_order . ' VALUES' . $save_value . $update_suffix;
                    if (db_execute($sql_execute)) {
                        array_push($return_array, "INSERT SUCCEEDED: Name: {$name}, Version: {$version}, sysDescr: {$sysDescrMatch}, sysObjectID: {$sysObjectID}");
                    } else {
                        array_push($return_array, "<strong>INSERT FAILED:</strong> Name: {$name}, Version: {$version}, sysDescr: {$sysDescrMatch}, sysObjectID: {$sysObjectID}");
                    }
                } else {
                    /* perform check to see if the row exists */
                    $existing_row = db_fetch_row("SELECT * FROM plugin_hmib_hrSystemTypes {$sql_where}");
                    if (sizeof($existing_row)) {
                        array_push($return_array, "<strong>INSERT SKIPPED, EXISTING:</strong> Name: {$name}, Vendor: {$vendor}, sysDescr: {$sysDescrMatch}, sysObjectID: {$sysObjectID}");
                    } else {
                        $sql_execute = 'INSERT INTO plugin_hmib_hrSystemTypes ' . $save_order . ' VALUES' . $save_value;
                        if (db_execute($sql_execute)) {
                            array_push($return_array, "INSERT SUCCEEDED: Name: {$name}, Version: {$version}, sysDescr: {$sysDescrMatch}, sysObjectID: {$sysObjectID}");
                        } else {
                            array_push($return_array, "<strong>INSERT FAILED:</strong> Name: {$name}, Version: {$version}, sysDescr: {$sysDescrMatch}, sysObjectID: {$sysObjectID}");
                        }
                    }
                }
            }
        }
        $i++;
    }
    return $return_array;
}