mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 00:04:37 +02:00
Added api for metaconsole. Ticket: #1474
This commit is contained in:
parent
52e6dda3b4
commit
95873d9356
815
pandora_console/include/functions_api.php
Normal file → Executable file
815
pandora_console/include/functions_api.php
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
@ -581,7 +581,7 @@ function events_comment ($id_event, $comment = '', $action = 'Added comment', $m
|
|||||||
$comments_format = 'new';
|
$comments_format = 'new';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch($comments_format) {
|
switch($comments_format) {
|
||||||
case 'new':
|
case 'new':
|
||||||
$comment_for_json['comment'] = $comment;
|
$comment_for_json['comment'] = $comment;
|
||||||
@ -677,36 +677,125 @@ function events_get_description ($id_event) {
|
|||||||
*
|
*
|
||||||
* @return int event id
|
* @return int event id
|
||||||
*/
|
*/
|
||||||
function events_create_event ($event, $id_group, $id_agent, $status = 0, $id_user = "", $event_type = "unknown", $priority = 0, $id_agent_module = 0, $id_aam = 0, $critical_instructions = '', $warning_instructions = '', $unknown_instructions = '', $source="Pandora", $tags="", $custom_data="") {
|
function events_create_event ($event, $id_group, $id_agent, $status = 0,
|
||||||
|
$id_user = "", $event_type = "unknown", $priority = 0,
|
||||||
|
$id_agent_module = 0, $id_aam = 0, $critical_instructions = '',
|
||||||
|
$warning_instructions = '', $unknown_instructions = '',
|
||||||
|
$source="Pandora", $tags="", $custom_data="", $server_id = 0) {
|
||||||
|
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
switch ($config["dbtype"]) {
|
$table_events = 'tevento';
|
||||||
case "mysql":
|
if (defined ('METACONSOLE')) {
|
||||||
$sql = sprintf ('INSERT INTO tevento (id_agente, id_grupo, evento, timestamp,
|
$table_events = 'tmetaconsole_event';
|
||||||
estado, utimestamp, id_usuario, event_type, criticity,
|
|
||||||
id_agentmodule, id_alert_am, critical_instructions, warning_instructions, unknown_instructions, source, tags, custom_data)
|
switch ($config["dbtype"]) {
|
||||||
VALUES (%d, %d, "%s", NOW(), %d, UNIX_TIMESTAMP(NOW()), "%s", "%s", %d, %d, %d, "%s", "%s", "%s", "%s", "%s", "%s")',
|
case "mysql":
|
||||||
$id_agent, $id_group, $event, $status, $id_user, $event_type,
|
$sql = sprintf ('
|
||||||
$priority, $id_agent_module, $id_aam, $critical_instructions, $warning_instructions, $unknown_instructions, $source, $tags, $custom_data);
|
INSERT INTO ' . $table_events . ' (id_agente, id_grupo, evento,
|
||||||
break;
|
timestamp, estado, utimestamp, id_usuario,
|
||||||
case "postgresql":
|
event_type, criticity, id_agentmodule, id_alert_am,
|
||||||
$sql = sprintf ('INSERT INTO tevento (id_agente, id_grupo, evento, timestamp,
|
critical_instructions, warning_instructions,
|
||||||
estado, utimestamp, id_usuario, event_type, criticity,
|
unknown_instructions, source, tags, custom_data,
|
||||||
id_agentmodule, id_alert_am, critical_instructions, warning_instructions, unknown_instructions, source, tags, custom_data)
|
server_id)
|
||||||
VALUES (%d, %d, "%s", NOW(), %d, ceil(date_part(\'epoch\', CURRENT_TIMESTAMP)), "%s", "%s", %d, %d, %d, "%s", "%s", "%s", "%s", "%s", "%s")',
|
VALUES (%d, %d, "%s", NOW(), %d, UNIX_TIMESTAMP(NOW()),
|
||||||
$id_agent, $id_group, $event, $status, $id_user, $event_type,
|
"%s", "%s", %d, %d, %d, "%s", "%s", "%s", "%s",
|
||||||
$priority, $id_agent_module, $id_aam, $critical_instructions, $warning_instructions, $unknown_instructions, $source, $tags, $custom_data);
|
"%s", "%s", %d)',
|
||||||
break;
|
$id_agent, $id_group, $event, $status, $id_user,
|
||||||
case "oracle":
|
$event_type, $priority, $id_agent_module, $id_aam,
|
||||||
$sql = sprintf ('INSERT INTO tevento (id_agente, id_grupo, evento, timestamp,
|
$critical_instructions, $warning_instructions,
|
||||||
estado, utimestamp, id_usuario, event_type, criticity,
|
$unknown_instructions, $source, $tags, $custom_data,
|
||||||
id_agentmodule, id_alert_am, critical_instructions, warning_instructions, unknown_instructions, source, tags, custom_data)
|
$server_id);
|
||||||
VALUES (%d, %d, "%s", CURRENT_TIMESTAMP, %d, ceil((sysdate - to_date(\'19700101000000\',\'YYYYMMDDHH24MISS\')) * (86400)), "%s", "%s", %d, %d, %d, "%s", "%s", "%s", "%s", "%s", "%s")',
|
break;
|
||||||
$id_agent, $id_group, $event, $status, $id_user, $event_type,
|
case "postgresql":
|
||||||
$priority, $id_agent_module, $id_aam, $critical_instructions, $warning_instructions, $unknown_instructions, $source, $tags, $custom_data);
|
$sql = sprintf ('
|
||||||
break;
|
INSERT INTO ' . $table_events . ' (id_agente, id_grupo, evento,
|
||||||
|
timestamp, estado, utimestamp, id_usuario,
|
||||||
|
event_type, criticity, id_agentmodule, id_alert_am,
|
||||||
|
critical_instructions, warning_instructions,
|
||||||
|
unknown_instructions, source, tags, custom_data,
|
||||||
|
server_id)
|
||||||
|
VALUES (%d, %d, "%s", NOW(), %d,
|
||||||
|
ceil(date_part(\'epoch\', CURRENT_TIMESTAMP)), "%s",
|
||||||
|
"%s", %d, %d, %d, "%s", "%s", "%s", "%s", "%s",
|
||||||
|
"%s", %d)',
|
||||||
|
$id_agent, $id_group, $event, $status, $id_user,
|
||||||
|
$event_type, $priority, $id_agent_module, $id_aam,
|
||||||
|
$critical_instructions, $warning_instructions,
|
||||||
|
$unknown_instructions, $source, $tags, $custom_data,
|
||||||
|
$server_id);
|
||||||
|
break;
|
||||||
|
case "oracle":
|
||||||
|
$sql = sprintf ('
|
||||||
|
INSERT INTO ' . $table_events . ' (id_agente, id_grupo, evento,
|
||||||
|
timestamp, estado, utimestamp, id_usuario,
|
||||||
|
event_type, criticity, id_agentmodule, id_alert_am,
|
||||||
|
critical_instructions, warning_instructions,
|
||||||
|
unknown_instructions, source, tags, custom_data,
|
||||||
|
server_id)
|
||||||
|
VALUES (%d, %d, "%s", CURRENT_TIMESTAMP, %d,
|
||||||
|
ceil((sysdate - to_date(\'19700101000000\',\'YYYYMMDDHH24MISS\')) * (86400)),
|
||||||
|
"%s", "%s", %d, %d, %d, "%s", "%s", "%s", "%s",
|
||||||
|
"%s", "%s", %d)',
|
||||||
|
$id_agent, $id_group, $event, $status, $id_user,
|
||||||
|
$event_type, $priority, $id_agent_module, $id_aam,
|
||||||
|
$critical_instructions, $warning_instructions,
|
||||||
|
$unknown_instructions, $source, $tags, $custom_data,
|
||||||
|
$server_id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
switch ($config["dbtype"]) {
|
||||||
|
case "mysql":
|
||||||
|
$sql = sprintf ('
|
||||||
|
INSERT INTO ' . $table_events . ' (id_agente, id_grupo, evento,
|
||||||
|
timestamp, estado, utimestamp, id_usuario,
|
||||||
|
event_type, criticity, id_agentmodule, id_alert_am,
|
||||||
|
critical_instructions, warning_instructions,
|
||||||
|
unknown_instructions, source, tags, custom_data)
|
||||||
|
VALUES (%d, %d, "%s", NOW(), %d, UNIX_TIMESTAMP(NOW()),
|
||||||
|
"%s", "%s", %d, %d, %d, "%s", "%s", "%s", "%s",
|
||||||
|
"%s", "%s")',
|
||||||
|
$id_agent, $id_group, $event, $status, $id_user,
|
||||||
|
$event_type, $priority, $id_agent_module, $id_aam,
|
||||||
|
$critical_instructions, $warning_instructions,
|
||||||
|
$unknown_instructions, $source, $tags, $custom_data);
|
||||||
|
break;
|
||||||
|
case "postgresql":
|
||||||
|
$sql = sprintf ('
|
||||||
|
INSERT INTO ' . $table_events . ' (id_agente, id_grupo, evento,
|
||||||
|
timestamp, estado, utimestamp, id_usuario,
|
||||||
|
event_type, criticity, id_agentmodule, id_alert_am,
|
||||||
|
critical_instructions, warning_instructions,
|
||||||
|
unknown_instructions, source, tags, custom_data)
|
||||||
|
VALUES (%d, %d, "%s", NOW(), %d,
|
||||||
|
ceil(date_part(\'epoch\', CURRENT_TIMESTAMP)), "%s",
|
||||||
|
"%s", %d, %d, %d, "%s", "%s", "%s", "%s", "%s",
|
||||||
|
"%s")',
|
||||||
|
$id_agent, $id_group, $event, $status, $id_user,
|
||||||
|
$event_type, $priority, $id_agent_module, $id_aam,
|
||||||
|
$critical_instructions, $warning_instructions,
|
||||||
|
$unknown_instructions, $source, $tags, $custom_data);
|
||||||
|
break;
|
||||||
|
case "oracle":
|
||||||
|
$sql = sprintf ('
|
||||||
|
INSERT INTO ' . $table_events . ' (id_agente, id_grupo, evento,
|
||||||
|
timestamp, estado, utimestamp, id_usuario,
|
||||||
|
event_type, criticity, id_agentmodule, id_alert_am,
|
||||||
|
critical_instructions, warning_instructions,
|
||||||
|
unknown_instructions, source, tags, custom_data)
|
||||||
|
VALUES (%d, %d, "%s", CURRENT_TIMESTAMP, %d,
|
||||||
|
ceil((sysdate - to_date(\'19700101000000\',\'YYYYMMDDHH24MISS\')) * (86400)),
|
||||||
|
"%s", "%s", %d, %d, %d, "%s", "%s", "%s", "%s",
|
||||||
|
"%s", "%s")',
|
||||||
|
$id_agent, $id_group, $event, $status, $id_user,
|
||||||
|
$event_type, $priority, $id_agent_module, $id_aam,
|
||||||
|
$critical_instructions, $warning_instructions,
|
||||||
|
$unknown_instructions, $source, $tags, $custom_data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) db_process_sql ($sql, "insert_id");
|
return (int) db_process_sql ($sql, "insert_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,10 +465,10 @@ function event_comment() {
|
|||||||
var params = [];
|
var params = [];
|
||||||
params.push("page=include/ajax/events");
|
params.push("page=include/ajax/events");
|
||||||
params.push("add_comment=1");
|
params.push("add_comment=1");
|
||||||
params.push("event_id="+event_id);
|
params.push("event_id=" + event_id);
|
||||||
params.push("comment="+comment);
|
params.push("comment=" + comment);
|
||||||
params.push("meta="+meta);
|
params.push("meta=" + meta);
|
||||||
params.push("history="+history);
|
params.push("history=" + history);
|
||||||
|
|
||||||
$('#button-comment_button').attr('disabled','disabled');
|
$('#button-comment_button').attr('disabled','disabled');
|
||||||
$('#response_loading').show();
|
$('#response_loading').show();
|
||||||
|
@ -163,10 +163,10 @@ if ($update_pressed || $open_filter) {
|
|||||||
$table = html_get_predefined_table('transparent', 2);
|
$table = html_get_predefined_table('transparent', 2);
|
||||||
$table->styleTable = 'width: 23px; float: right; background: #ECECEC;';
|
$table->styleTable = 'width: 23px; float: right; background: #ECECEC;';
|
||||||
$table->width = '98%';
|
$table->width = '98%';
|
||||||
$table->style[0] = 'text-align:left;';
|
$table->style[0] = 'text-align: left;';
|
||||||
$table->style[1] = 'text-align:right;';
|
$table->style[1] = 'text-align: right;';
|
||||||
|
|
||||||
$table->data[0][1] = '<a id="events_graph_link" href="javascript:show_events_graph_dialog()">' . html_print_image('images/chart_curve.png', true, array('title' => __('Show events graph'))) . '</a>';
|
$table->data[0][1] = '<a id="events_graph_link" href="javascript: show_events_graph_dialog()">' . html_print_image('images/chart_curve.png', true, array('title' => __('Show events graph'))) . '</a>';
|
||||||
$table->cellstyle[0][1] = 'background: #ECECEC;';
|
$table->cellstyle[0][1] = 'background: #ECECEC;';
|
||||||
|
|
||||||
html_print_table($table);
|
html_print_table($table);
|
||||||
@ -610,7 +610,8 @@ enterprise_hook('close_meta_frame');
|
|||||||
unset($table);
|
unset($table);
|
||||||
|
|
||||||
// Values to be used from javascript library
|
// Values to be used from javascript library
|
||||||
html_print_input_hidden('ajax_file', ui_get_full_url("ajax.php", false, false, false));
|
html_print_input_hidden('ajax_file',
|
||||||
|
ui_get_full_url("ajax.php", false, false, false));
|
||||||
html_print_input_hidden('meta', (int)$meta);
|
html_print_input_hidden('meta', (int)$meta);
|
||||||
html_print_input_hidden('history', (int)$history);
|
html_print_input_hidden('history', (int)$history);
|
||||||
|
|
||||||
|
@ -33,18 +33,23 @@ Where options:\n
|
|||||||
-create_event
|
-create_event
|
||||||
-name <event_name> : Free text
|
-name <event_name> : Free text
|
||||||
-group <id_group> : Group ID (use 0 for 'all')
|
-group <id_group> : Group ID (use 0 for 'all')
|
||||||
-agent :Agent ID
|
-agent : Agent ID
|
||||||
|
|
||||||
Optional parameters:
|
Optional parameters:
|
||||||
|
|
||||||
[-status <status>] : 0 New, 1 Validated, 2 In process
|
[-status <status>] : 0 New, 1 Validated, 2 In process
|
||||||
[-user <id_user>] : User comment (use in combination with -comment option)
|
[-user <id_user>] : User comment (use in combination with -comment option)
|
||||||
[type <event_type>] : unknown, alert_fired, alert_recovered, alert_ceased
|
[-type <event_type>] : unknown, alert_fired, alert_recovered, alert_ceased
|
||||||
alert_manual_validation, system, error, new_agent
|
alert_manual_validation, system, error, new_agent
|
||||||
configuration_change, going_unknown, going_down_critical,
|
configuration_change, going_unknown, going_down_critical,
|
||||||
going_down_warning, going_up_normal
|
going_down_warning, going_up_normal
|
||||||
[-criticity <criticity>] : 0 Maintance, 1 Informative, 2 Normal,
|
[-criticity <criticity>] : 0 Maintance,
|
||||||
3 Warning, 4 Crit, 5 Minor, 6 Major
|
1 Informative,
|
||||||
|
2 Normal,
|
||||||
|
3 Warning,
|
||||||
|
4 Crit,
|
||||||
|
5 Minor,
|
||||||
|
6 Major
|
||||||
[-am <id_agent_module>] : ID Agent Module linked to event
|
[-am <id_agent_module>] : ID Agent Module linked to event
|
||||||
[-alert <id_alert_am>] : ID Alert Module linked to event
|
[-alert <id_alert_am>] : ID Alert Module linked to event
|
||||||
[-c_instructions <critical_instructions>]
|
[-c_instructions <critical_instructions>]
|
||||||
@ -53,19 +58,15 @@ Optional parameters:
|
|||||||
[-user_comment <comment>]
|
[-user_comment <comment>]
|
||||||
[-owner_user <user for the event>]
|
[-owner_user <user for the event>]
|
||||||
[-source <source>] : (By default 'Pandora')
|
[-source <source>] : (By default 'Pandora')
|
||||||
[-tag <tags>] : Tag (must exist in the system to be imported)";
|
[-tag <tags>] : Tag (must exist in the system to be imported)
|
||||||
|
[-custom_data <custom_data>]: Custom data should be a base 64 encoded JSON document
|
||||||
|
[-server_id <server_id>] : The pandora node server_id";
|
||||||
|
|
||||||
print "Credential/API syntax: \n\n\t";
|
print "Credential/API syntax: \n\n\t";
|
||||||
print "<credentials>: API credentials separated by comma: <api_pass>,<user>,<pass>\n\n";
|
print "<credentials>: API credentials separated by comma: <api_pass>,<user>,<pass>\n\n";
|
||||||
|
|
||||||
print "Example of event generation:\n\n";
|
print "Example of event generation:\n\n";
|
||||||
|
|
||||||
#~ print "\t./pandora_revent.pl -p http://192.168.70.160/pandora_console/include/api.php -u pot12,admin,pandora \
|
|
||||||
#~ \t-create_event -name \"Sample event executed from commandline\" -group 2 -type \"system\" -agent 2 \
|
|
||||||
#~ \t-user \"admin\" -status 0 -am 0 -alert 9 -criticity 3 -comment \"User comments\" -tag \"tags\" \
|
|
||||||
#~ \t-source \"Commandline\" -extra 3 -c_instructions \"Critical instructions\" \
|
|
||||||
#~ \t-w_instructions \"Warning instructions\" -u_instructions \"Unknown instructions\" -owner \"other\" ";
|
|
||||||
|
|
||||||
print "\t./pandora_revent.pl -p http://localhost/pandora_console/include/api.php -u 1234,admin,pandora \
|
print "\t./pandora_revent.pl -p http://localhost/pandora_console/include/api.php -u 1234,admin,pandora \
|
||||||
\t-create_event -name \"SampleEvent\" -group 2 -agent 189 -status 0 -user \"admin\" -type \"system\" \
|
\t-create_event -name \"SampleEvent\" -group 2 -agent 189 -status 0 -user \"admin\" -type \"system\" \
|
||||||
\t-criticity 3 -am 0 -alert 9 -c_instructions \"Critical instructions\" -w_instructions \"Warning instructions\" \
|
\t-criticity 3 -am 0 -alert 9 -c_instructions \"Critical instructions\" -w_instructions \"Warning instructions\" \
|
||||||
@ -136,6 +137,8 @@ sub tool_api_main () {
|
|||||||
my $id_event;
|
my $id_event;
|
||||||
my $option = $ARGV[4];
|
my $option = $ARGV[4];
|
||||||
my $call_api;
|
my $call_api;
|
||||||
|
my $custom_data = "";
|
||||||
|
my $server_id = 0;
|
||||||
|
|
||||||
#~ help or api path (required)
|
#~ help or api path (required)
|
||||||
if ($ARGV[0] eq '-h') {
|
if ($ARGV[0] eq '-h') {
|
||||||
@ -232,6 +235,12 @@ sub tool_api_main () {
|
|||||||
if ($line eq '-owner_user') {
|
if ($line eq '-owner_user') {
|
||||||
$owner_user = $ARGV[$i + 1];
|
$owner_user = $ARGV[$i + 1];
|
||||||
}
|
}
|
||||||
|
if ($line eq '-custom_data') {
|
||||||
|
$custom_data = $ARGV[$i + 1];
|
||||||
|
}
|
||||||
|
if ($line eq '-server_id') {
|
||||||
|
$server_id = $ARGV[$i + 1];
|
||||||
|
}
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
@ -264,7 +273,10 @@ sub tool_api_main () {
|
|||||||
"|" . $user_comment .
|
"|" . $user_comment .
|
||||||
"|" . $owner_user .
|
"|" . $owner_user .
|
||||||
"|" . $source .
|
"|" . $source .
|
||||||
"|" . $tags;
|
"|" . $tags .
|
||||||
|
"|" . $custom_data .
|
||||||
|
"|" . $server_id;
|
||||||
|
|
||||||
$call_api = $api_path . '?' .
|
$call_api = $api_path . '?' .
|
||||||
'op=set&' .
|
'op=set&' .
|
||||||
'op2=create_event&' .
|
'op2=create_event&' .
|
||||||
|
Loading…
x
Reference in New Issue
Block a user