Merge branch 'ent-9447-control-de-entrada-en-cli-create_event' into 'develop'

Ent 9447 control de entrada en cli create event

See merge request artica/pandorafms!5221
This commit is contained in:
Rafael Ameijeiras 2022-12-12 22:51:11 +00:00
commit 1fdd29970a
1 changed files with 102 additions and 2 deletions

View File

@ -21,7 +21,7 @@ use JSON qw(decode_json encode_json);
use MIME::Base64;
use Encode qw(decode encode_utf8);
use LWP::Simple;
#use Data::Dumper;
use Data::Dumper;
# Default lib dir for RPM and DEB packages
BEGIN { push @INC, '/usr/lib/perl5'; }
@ -1294,6 +1294,58 @@ sub help_screen_line($$$){
print "\n\t$option $parameters : $help.\n" unless ($param ne '' && $param ne $option);
}
sub check_values($) {
my ($check) = @_;
use experimental 'smartmatch';
my $arg_cont = 2;
my $cont = 0;
my @args = @ARGV;
my $total = $#args;
while ($arg_cont <= $total) {
# Check type.
if ($check->[$cont]->{'type'} eq 'json') {
my $json_out = eval { decode_json($args[$arg_cont]) };
if ($@)
{
print "\nValue `$args[$arg_cont]` is an invalid json. \nError:$@\n";
exit;
}
}
# Check values.
if (defined($check->[$cont]->{'values'})) {
if (!($args[$arg_cont] ~~ $check->[$cont]->{'values'})) {
print "\nError: value `$args[$arg_cont]` is not valid for $check->[$cont]->{'name'}\n";
print "\tAvailable options: \t$check->[$cont]->{'values'}->[0]";
if (defined($check->[$cont]->{'text_extra'}->[0])) {
print " $check->[$cont]->{'text_extra'}->[0]";
}
print "\n";
my $cont_aux = 1;
my $while = 'false';
while ($while eq 'false') {
if (defined($check->[$cont]->{'values'}->[$cont_aux])) {
print "\t\t\t\t$check->[$cont]->{'values'}->[$cont_aux]";
if (defined($check->[$cont]->{'text_extra'}->[$cont_aux])) {
print " $check->[$cont]->{'text_extra'}->[$cont_aux]";
}
print "\n";
} else {
exit;
}
$cont_aux++;
}
}
}
$cont++;
$arg_cont++;
}
}
###############################################################################
###############################################################################
# CLI FUNCTIONS
@ -7812,9 +7864,57 @@ sub pandora_manage_main ($$$) {
cli_delete_profile();
}
elsif ($param eq '--create_event') {
my @fields = (
{'name' => 'event'},
{
'name' => 'event_type',
'values' => [
'unknown','alert_fired','alert_recovered','alert_ceased',
'alert_manual_validation','recon_host_detected','system',
'error','new_agent','going_up_warning','going_up_critical','going_down_warning',
'going_down_normal','going_down_critical','going_up_normal','configuration_change'
]
},
{'name' => 'group_name'},
{'name' => 'agent_name'},
{'name' => 'module_name'},
{
'name' => 'event_status',
'values' => ['0', '1', '2'],
'text_extra' => ['(New)', '(Validated)', '(In process)']
},
{
'name' => 'severity',
'values' => ['0', '1', '2', '3', '4', '5', '6'],
'text_extra' => [
'(Maintenance)', '(Informational)', '(Normal)',
'(Warning)', '(Critical)', '(Minor)', '(Major)'
]
},
{'name' => 'template_name'},
{'name' => 'user_name'},
{'name' => 'comment'},
{'name' => 'source'},
{'name' => 'id_extra'},
{'name' => 'tags'},
{'type' => 'json', 'name' => 'custom_data_json'},
{
'name' => 'force_create_agent',
'values' => ['0', '1']
},
{'name' => 'critical_instructions'},
{'name' => 'warning_instructions'},
{'name' => 'unknown_instructions'},
{'name' => 'use_alias'},
{'name' => 'metaconsole'}
);
param_check($ltotal, 20, 17);
check_values(\@fields);
cli_create_event();
}
}
elsif ($param eq '--validate_event') {
param_check($ltotal, 8, 7);
cli_validate_event();