mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
2010-06-23 Ramon Novoa <rnovoa@artica.es>
* pandora_agent: Added the module_save and module_condition features. See http://www.openideas.info/wiki/ for more information. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2924 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
1cd4a85037
commit
db161a7e41
@ -1,3 +1,8 @@
|
|||||||
|
2010-06-23 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
|
* pandora_agent: Added the module_save and module_condition features.
|
||||||
|
See http://www.openideas.info/wiki/ for more information.
|
||||||
|
|
||||||
2010-06-14 Junichi Satoh <junichi@rworks.jp>
|
2010-06-14 Junichi Satoh <junichi@rworks.jp>
|
||||||
|
|
||||||
* pandora_agent_installer: Set execute bit to startup script for
|
* pandora_agent_installer: Set execute bit to startup script for
|
||||||
|
@ -233,7 +233,9 @@ sub read_config (;$) {
|
|||||||
'counter' => 0,
|
'counter' => 0,
|
||||||
'max' => 0,
|
'max' => 0,
|
||||||
'min' => 0,
|
'min' => 0,
|
||||||
'postprocess' => 0
|
'postprocess' => 0,
|
||||||
|
'save' => '',
|
||||||
|
'actions' => []
|
||||||
};
|
};
|
||||||
} elsif ($line =~ /^\s*module_name\s+(.+)$/) {
|
} elsif ($line =~ /^\s*module_name\s+(.+)$/) {
|
||||||
$module->{'name'} = $1;
|
$module->{'name'} = $1;
|
||||||
@ -279,6 +281,20 @@ sub read_config (;$) {
|
|||||||
$module->{'counter'} = $1;
|
$module->{'counter'} = $1;
|
||||||
} elsif ($line =~ /^\s*module_timeout\s+(\d+)\s*$/) {
|
} elsif ($line =~ /^\s*module_timeout\s+(\d+)\s*$/) {
|
||||||
$module->{'timeout'} = $1;
|
$module->{'timeout'} = $1;
|
||||||
|
} elsif ($line =~ /^\s*module_save\s+(\w+)$/) {
|
||||||
|
$module->{'save'} = $1;
|
||||||
|
} elsif ($line =~ /^\s*module_condition\s+(.*)$/) {
|
||||||
|
my $action = $1;
|
||||||
|
# Numeric comparison
|
||||||
|
if ($action =~ /^\s*([<>!=]+)\s+(\d+\.\d*)\s+(.*)$/) {
|
||||||
|
push (@{$module->{'conditions'}}, {'operator' => $1, 'value_1' => $2, 'command' => $3});
|
||||||
|
# Interval
|
||||||
|
} elsif ($action =~ /^\s*[(]\s*(\d+\.\d*)\s*,\s*(\d+\.\d*)\s*[)]\s+(.*)$/) {
|
||||||
|
push (@{$module->{'conditions'}}, {'operator' => '()', 'value_1' => $1, 'value_2' => $2, 'command' => $3});
|
||||||
|
# Regular expression
|
||||||
|
} elsif ($action =~ /^\s*=~\s+(\S*)\s+(.*)$/) {
|
||||||
|
push (@{$module->{'conditions'}}, {'operator' => '=~', 'value_1' => $1, 'command' => $2});
|
||||||
|
}
|
||||||
} elsif ($line =~ /^\s*module_end\s*$/) {
|
} elsif ($line =~ /^\s*module_end\s*$/) {
|
||||||
next unless ($module->{'name'} ne '') and ($module->{'func'} != 0);
|
next unless ($module->{'name'} ne '') and ($module->{'func'} != 0);
|
||||||
push (@Modules, $module);
|
push (@Modules, $module);
|
||||||
@ -625,7 +641,18 @@ sub exec_module ($) {
|
|||||||
no strict 'refs';
|
no strict 'refs';
|
||||||
|
|
||||||
# Run
|
# Run
|
||||||
return &{$module->{'func'}}($module);
|
my @value = &{$module->{'func'}}($module);
|
||||||
|
|
||||||
|
# Save the module value if needed (only works for the first returned value)
|
||||||
|
if ($module->{'save'} ne '') {
|
||||||
|
if (defined ($value[0])) {
|
||||||
|
$ENV{$module->{'save'}} = $value[0] ;
|
||||||
|
} else {
|
||||||
|
$ENV{$module->{'save'}} = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return @value;
|
||||||
}
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
@ -730,6 +757,9 @@ sub module_exec ($) {
|
|||||||
# Something went wrong or no data
|
# Something went wrong or no data
|
||||||
return () unless ($? eq 0 && defined ($data[0]));
|
return () unless ($? eq 0 && defined ($data[0]));
|
||||||
|
|
||||||
|
# Evaluate module actions
|
||||||
|
evaluate_module_conditions ($module, $data[0]);
|
||||||
|
|
||||||
return @data;
|
return @data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -878,6 +908,25 @@ sub module_freepercentmemory ($) {
|
|||||||
return sprintf (("%d", $avail * 100 / $total));
|
return sprintf (("%d", $avail * 100 / $total));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Evaluate and execute module conditions.
|
||||||
|
################################################################################
|
||||||
|
sub evaluate_module_conditions ($$) {
|
||||||
|
my ($module, $data) = @_;
|
||||||
|
|
||||||
|
# Evaluate conditions
|
||||||
|
foreach my $condition (@{$module->{'conditions'}}) {
|
||||||
|
if (($condition->{'operator'} eq '>' && $data > $condition->{'value_1'}) ||
|
||||||
|
($condition->{'operator'} eq '<' && $data < $condition->{'value_1'}) ||
|
||||||
|
($condition->{'operator'} eq '=' && $data == $condition->{'value_1'}) ||
|
||||||
|
($condition->{'operator'} eq '!=' && $data != $condition->{'value_1'}) ||
|
||||||
|
($condition->{'operator'} eq '=~' && $data =~ /$condition->{'value_1'}/) ||
|
||||||
|
($condition->{'operator'} eq '()' && $data > $condition->{'value_1'} && $data < $condition->{'value_2'})) {
|
||||||
|
`$condition->{'command'} 2> /dev/null`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Main.
|
# Main.
|
||||||
################################################################################
|
################################################################################
|
||||||
|
Loading…
x
Reference in New Issue
Block a user