From 9a6378f694b56fe5586ad26e1ed3be40584d6672 Mon Sep 17 00:00:00 2001 From: hkosaka Date: Wed, 19 Dec 2012 08:48:12 +0000 Subject: [PATCH] 2012-12-19 Hirofumi Kosaka * include/functions_api.php: Added function 'api_get_pandora_servers'. * include/functions_servers.php: Fixed a type. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7304 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 7 ++ pandora_console/include/functions_api.php | 65 +++++++++++++++++++ pandora_console/include/functions_servers.php | 4 +- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 3a35b84b43..691298557a 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,10 @@ +2012-12-19 Hirofumi Kosaka + + * include/functions_api.php: Added function + 'api_get_pandora_servers'. + + * include/functions_servers.php: Fixed a type. + 2012-12-18 Juan Manuel Ramon * include/functions_reporting.php diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 3243ab238c..b0940e15b1 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -28,6 +28,7 @@ include_once($config['homedir'] . "/include/functions_events.php"); include_once($config['homedir'] . "/include/functions_groups.php"); include_once($config['homedir'] . "/include/functions_network_components.php"); include_once($config['homedir'] . "/include/functions_netflow.php"); +include_once($config['homedir'] . "/include/functions_servers.php"); enterprise_include_once ('include/functions_local_components.php'); /** @@ -5668,4 +5669,68 @@ function api_set_validate_event_by_id ($id, $trash1, $trash2, $returnType) { returnData($returnType, $data); return; } + +/** + * + * @param $trash1 + * @param $trash2 + * @param array $other it's array, but only is available. + * @param $returnType + * + */ +// http://localhost/pandora_console/include/api.php?op=get&op2=pandora_servers&return_type=csv&apipass=1234&user=admin&pass=pandora +function api_get_pandora_servers($trash1, $trash2, $other, $returnType) { + + if (!isset($other['data'][0])) + $separator = ';'; // by default + else + $separator = $other['data'][0]; + + $servers = servers_get_info (); + + foreach ($servers as $server) { + $dd = array ( + 'name' => $server["name"], + 'status' => $server["status"], + 'type' => $server["type"], + 'master' => $server["master"], + 'modules' => $server["modules"], + 'modules_total' => $server["modules_total"], + 'lag' => $server["lag"], + 'module_lag' => $server["module_lag"], + 'threads' => $server["threads"], + 'queued_modules' => $server["queued_modules"], + 'keepalive' => $server['keepalive'] + ); + + // servers_get_info() returns "servername" for recon server's name. + // i don't know why and the following line is a temprary workaround... + $dd["name"] = preg_replace( '/<[^>]*>/', "", $dd["name"]); + + switch ($dd['type']) { + case "snmp": + case "event": + $dd['modules'] = ''; + $dd['modules_total'] = ''; + $dd['lag'] = ''; + $dd['module_lag'] = ''; + break; + case "export": + $dd['lag'] = ''; + $dd['module_lag'] = ''; + break; + default: + break; + } + + $returnVar[] = $dd; + } + + $data = array('type' => 'array', 'data' => $returnVar); + + returnData($returnType, $data, $separator); + return; + +} + ?> diff --git a/pandora_console/include/functions_servers.php b/pandora_console/include/functions_servers.php index 178380d6b1..2e8a31db2f 100644 --- a/pandora_console/include/functions_servers.php +++ b/pandora_console/include/functions_servers.php @@ -240,7 +240,7 @@ function servers_get_info ($id_server = -1) { // --------------------------------------------------------------- $server["lag"] = db_get_sql ("SELECT lag_time FROM tserver WHERE id_server = ".$server["id_server"]); - $server["modulelag"] = db_get_sql ("SELECT lag_modules FROM tserver WHERE id_server = ".$server["id_server"]); + $server["module_lag"] = db_get_sql ("SELECT lag_modules FROM tserver WHERE id_server = ".$server["id_server"]); $server["modules"] = db_get_sql ("SELECT my_modules FROM tserver WHERE id_server = ".$server["id_server"]); $server["modules_total"] = db_get_sql ("SELECT total_modules_running FROM tserver WHERE id_server = ".$server["id_server"]); @@ -543,4 +543,4 @@ function servers_get_status ($id_server) { $serverinfo = servers_get_info ($id_server); return $serverinfo[$id_server]; } -?> \ No newline at end of file +?>