close(); } } print $output; } function get_snmp_data_walk() { $host_id = get_filter_request_var('host_id'); $oid = get_nfilter_request_var('oid'); if (!empty($host_id)) { $host = db_fetch_row_prepared('SELECT * FROM host WHERE id = ?', array($host_id)); $session = cacti_snmp_session($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_engine_id'], $host['snmp_port'], $host['snmp_timeout'], $host['ping_retries'], $host['max_oids']); if ($session === false) { $output = 'U'; }else{ $output = cacti_snmp_session_walk($session, $oid); $session->close(); } } if (sizeof($output)) { print json_encode($output); }else{ print 'U'; } } function ping_device() { $host_id = get_filter_request_var('host_id'); api_device_ping_device($host_id, true); } function poll_for_data() { $local_data_id = get_filter_request_var('local_data_id'); $host_id = get_filter_request_var('host_id'); $item = db_fetch_row_prepared('SELECT * FROM poller_item WHERE host_id = ? AND local_data_id = ?', array($host_id, $local_data_id)); if (sizeof($item)) { switch ($item['action']) { case POLLER_ACTION_SNMP: /* snmp */ if (($item['snmp_version'] == 0) || (($item['snmp_community'] == '') && ($item['snmp_version'] != 3))) { $output = 'U'; }else { $host = db_fetch_row_prepared('SELECT ping_retries, max_oids FROM host WHERE hostname = ?', array($item['hostname'])); $session = cacti_snmp_session($item['hostname'], $item['snmp_community'], $item['snmp_version'], $item['snmp_username'], $item['snmp_password'], $item['snmp_auth_protocol'], $item['snmp_priv_passphrase'], $item['snmp_priv_protocol'], $item['snmp_context'], $item['snmp_engine_id'], $item['snmp_port'], $item['snmp_timeout'], $host['ping_retries'], $host['max_oids']); if ($session === false) { $output = 'U'; }else{ $output = cacti_snmp_session_get($session, $item['arg1']); $session->close(); } if (prepare_validate_result($output) === false) { if (strlen($output) > 20) { $strout = 20; } else { $strout = strlen($output); } $output = 'U'; } } break; case POLLER_ACTION_SCRIPT: /* script (popen) */ $output = trim(exec_poll($item['arg1'])); if (prepare_validate_result($output) === false) { if (strlen($output) > 20) { $strout = 20; } else { $strout = strlen($output); } $output = 'U'; } break; case POLLER_ACTION_SCRIPT_PHP: /* script (php script server) */ $cactides = array( 0 => array('pipe', 'r'), // stdin is a pipe that the child will read from 1 => array('pipe', 'w'), // stdout is a pipe that the child will write to 2 => array('pipe', 'w') // stderr is a pipe to write to ); if (function_exists('proc_open')) { $cactiphp = proc_open(read_config_option('path_php_binary') . ' -q ' . $config['base_path'] . '/script_server.php realtime', $cactides, $pipes); $output = fgets($pipes[1], 1024); $using_proc_function = true; }else { $using_proc_function = false; } if ($using_proc_function == true) { $output = trim(str_replace("\n", '', exec_poll_php($item['arg1'], $using_proc_function, $pipes, $cactiphp))); if (prepare_validate_result($output) === false) { if (strlen($output) > 20) { $strout = 20; } else { $strout = strlen($output); } $output = 'U'; } }else{ $output = 'U'; } if (($using_proc_function == true) && ($script_server_calls > 0)) { /* close php server process */ fwrite($pipes[0], "quit\r\n"); fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); $return_value = proc_close($cactiphp); } break; } } print $output; } function run_remote_data_query() { $host_id = get_filter_request_var('host_id'); $data_query_id = get_filter_request_var('data_query_id'); if ($host_id > 0 && $data_query_id > 0) { run_data_query($host_id, $data_query_id); } }