__('Add Device')
);
$os_arr = array_rekey(db_fetch_assoc('SELECT DISTINCT os
FROM automation_devices
WHERE os IS NOT NULL AND os!=""'), 'os', 'os');
$status_arr = array(
__('Down'),
__('Up')
);
$networks = array_rekey(db_fetch_assoc('SELECT an.id, an.name
FROM automation_networks AS an
INNER JOIN automation_devices AS ad
ON an.id=ad.network_id
ORDER BY name'), 'id', 'name');
set_default_action();
process_request_vars();
switch(get_request_var('action')) {
case 'purge':
purge_discovery_results();
break;
case 'actions':
form_actions();
break;
case 'export':
export_discovery_results();
break;
default:
display_discovery_page();
break;
}
function form_actions() {
global $device_actions, $availability_options;
/* ================= input validation ================= */
get_filter_request_var('drp_action', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-zA-Z0-9_]+)$/')));
/* ==================================================== */
/* if we are to save this form, instead of display it */
if (isset_request_var('selected_items')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
if (get_nfilter_request_var('drp_action') == '1') { /* add to cacti */
foreach($selected_items as $id) {
$d = db_fetch_row_prepared('SELECT * FROM automation_devices WHERE id = ?', array($id));
$d['poller_id'] = get_filter_request_var('poller_id');
$d['host_template'] = get_filter_request_var('host_template');
$d['availability_method'] = get_filter_request_var('availability_method');
$d['notes'] = __('Added manually through device automation interface.');
$d['snmp_sysName'] = $d['sysName'];
// pull ping options from network_id
$n = db_fetch_row_prepared('SELECT * FROM automation_networks WHERE id = ?', array($d['network_id']));
if (cacti_sizeof($n)) {
$d['ping_method'] = $n['ping_method'];
$d['ping_port'] = $n['ping_port'];
$d['ping_timeout'] = $n['ping_timeout'];
$d['ping_retries'] = $n['ping_retries'];
}
$host_id = automation_add_device($d, true);
$description = (trim($d['hostname']) != '' ? $d['hostname'] : $d['ip']);
if ($host_id) {
$message = "" . __('Device') . ' ' . html_escape($description) . ' ' . __('Added to Cacti') . ' ';
} else {
$message = "" . __('Device') . ' ' . html_escape($description) . ' ' . __('Not Added to Cacti') . ' ';
}
}
if ($message != '') {
$_SESSION['automation_message'] = $message;
raise_message('automation_message');
}
}
}
header('Location: automation_devices.php?header=false');
exit;
}
/* setup some variables */
$device_list = ''; $device_array = array(); $i = 0;
/* loop through each of the graphs selected on the previous page and get more info about them */
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
$device_list .= '
' . html_escape(db_fetch_cell_prepared('SELECT CONCAT(IF(hostname!="", hostname, "unknown"), " (", ip, ")") FROM automation_devices WHERE id = ?', array($matches[1]))) . '
';
$device_array[$i] = $matches[1];
$i++;
}
}
top_header();
form_start('automation_devices.php', 'chk');
html_start_box($device_actions{get_request_var('drp_action')}, '60%', '', '3', 'center', '');
$available_host_templates = db_fetch_assoc_prepared('SELECT id, name FROM host_template ORDER BY name');
if (isset($device_array) && cacti_sizeof($device_array)) {
if (get_request_var('drp_action') == '1') { /* add */
$pollers = db_fetch_assoc_prepared('SELECT id, name FROM poller ORDER BY name');
$availability_method = 0;
$host_template = 0;
$devices = db_fetch_assoc('SELECT id, sysName, sysDescr FROM automation_devices WHERE id IN (' . implode(',', $device_array) . ')');
foreach ($devices as $device) {
$os = automation_find_os($device['sysDescr'], '', $device['sysName']);
if (isset($os['host_template']) && $os['host_template'] > 0) {
if ($host_template == 0) {
$host_template = $os['host_template'];
$availability_method = $os['availability_method'];
} else if ($host_template != $os['host_template']) {
// End up here if we have 2 devices with different Host Template matches
$host_template = 0;
$availability_method = 0;
break;
}
} else {
// Couldn't determine the Host Template for a device, so abort and don't set a default
$host_template = 0;
$availability_method = 0;
break;
}
}
print "
" . __('Click \'Continue\' to add the following Discovered device(s).') . "