PluginTools: New methods
- Added extract_key_map - Added read_configuration
This commit is contained in:
parent
831e621c6a
commit
c4f9723d0d
|
@ -4,6 +4,12 @@ package PandoraFMS::PluginTools;
|
||||||
# Pandora FMS Plugin functions library
|
# Pandora FMS Plugin functions library
|
||||||
#
|
#
|
||||||
# (c) Fco de Borja Sanchez <fborja.sanchez@artica.es>
|
# (c) Fco de Borja Sanchez <fborja.sanchez@artica.es>
|
||||||
|
#
|
||||||
|
# Requirements:
|
||||||
|
# Library Centos package
|
||||||
|
# ------- --------------
|
||||||
|
# LWP::UserAgent perl-libwww-perl
|
||||||
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Version Date
|
# Version Date
|
||||||
|
@ -47,6 +53,7 @@ our @EXPORT = qw(
|
||||||
decrypt
|
decrypt
|
||||||
empty
|
empty
|
||||||
encrypt
|
encrypt
|
||||||
|
extract_key_map
|
||||||
get_lib_version
|
get_lib_version
|
||||||
get_unit
|
get_unit
|
||||||
get_unix_time
|
get_unix_time
|
||||||
|
@ -71,6 +78,7 @@ our @EXPORT = qw(
|
||||||
print_module
|
print_module
|
||||||
print_warning
|
print_warning
|
||||||
print_stderror
|
print_stderror
|
||||||
|
read_configuration
|
||||||
simple_decode_json
|
simple_decode_json
|
||||||
snmp_data_switcher
|
snmp_data_switcher
|
||||||
snmp_get
|
snmp_get
|
||||||
|
@ -240,6 +248,25 @@ sub empty {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Assing a value to a string key as subkeys in a hash map
|
||||||
|
################################################################################
|
||||||
|
sub extract_key_map;
|
||||||
|
sub extract_key_map {
|
||||||
|
my ($hash, $string, $value) = @_;
|
||||||
|
|
||||||
|
my ($key, $str) = split /\./, $string, 2;
|
||||||
|
if (empty($str)) {
|
||||||
|
$hash->{$key} = $value;
|
||||||
|
|
||||||
|
return $hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
$hash->{$key} = extract_key_map($hash->{$key}, $str, $value);
|
||||||
|
|
||||||
|
return $hash;
|
||||||
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Check if a value is in an array
|
# Check if a value is in an array
|
||||||
################################################################################
|
################################################################################
|
||||||
|
@ -900,6 +927,20 @@ sub get_sys_environment {
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Parses any configuration, from file (1st arg to program) or direct arguments
|
||||||
|
################################################################################
|
||||||
|
sub read_configuration {
|
||||||
|
my ($config, $separator, $custom_eval) = @_;
|
||||||
|
|
||||||
|
if ((!empty(@ARGV)) && (-f $ARGV[0])) {
|
||||||
|
$config = merge_hashes($config, parse_configuration(shift @ARGV, $separator, $custom_eval));
|
||||||
|
}
|
||||||
|
$config = merge_hashes($config, parse_arguments(\@ARGV));
|
||||||
|
|
||||||
|
return $config;
|
||||||
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# General arguments parser
|
# General arguments parser
|
||||||
################################################################################
|
################################################################################
|
||||||
|
@ -970,7 +1011,7 @@ sub parse_configuration {
|
||||||
$f = 1;
|
$f = 1;
|
||||||
my $aux;
|
my $aux;
|
||||||
eval {
|
eval {
|
||||||
$aux = $item->{target}->($item->{exp},$line);
|
$aux = $item->{target}->($_config, $item->{exp}, $line);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (empty($_config)) {
|
if (empty($_config)) {
|
||||||
|
|
Loading…
Reference in New Issue