Skip to content

Commit

Permalink
agents: improve extra opts and merge with args
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Jan 17, 2024
1 parent ed34833 commit c17bc44
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
37 changes: 16 additions & 21 deletions plugins/plugins-available/agents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,39 +112,34 @@ For example:
name = httpd
</proc>

# set default args (if multiple args match, the last one overrides previous ones)
# set extra service attributes (if multiple blocks match, each is applied in order and overwrites previous values)
# block can be used multiple times
<args>
value = warn='load > 95' crit='load > 100'
match = cpu # regex match on service name
<extra_service_opts>
service = ^cpu$ # regex match on service description
# restrict to specific hosts (regular expression)
#host = ANY
#section ~ test # apply this argument only to sections containing "test"
</args>
#section ~ test # apply this attributes only to sections containing "test"

# can be used to append extra arguments to the command line
#args = warn='load > 95' crit='load > 100'

# naemon service attributes will be added to the generated host configuration
first_notification_delay = 30
notification_options = w,c
# other naemon service attributes...
</extra_service_opts>

# set extra host attributes (if multiple blocks match, each is applied in order)
# block can be used multiple times
<extra_host_opts>
match = hostname # regex match on host name
host = ^hostname$ # regex match on host name
#section ~ test # apply this attributes only to sections containing "test"

# naemon host attributes will be added to the generated host configuration
#first_notification_delay = 30
# other attributes...
#check_command = check-host-alive!$HOSTADDRESS$
# other naemon host attributes...
</extra_host_opts>

# set extra service attributes (if multiple blocks match, each is applied in order)
# block can be used multiple times
<extra_service_opts>
match = service description # regex match on service description
# restrict to specific hosts (regular expression)
#host = ANY
#section ~ test # apply this attributes only to sections containing "test"

# naemon service attributes will be added to the generated host configuration
first_notification_delay = 30
# other attributes...
</extra_service_opts>

</snclient>
</Component>
11 changes: 9 additions & 2 deletions plugins/plugins-available/agents/lib/Thruk/Agents/SNClient.pm
Original file line number Diff line number Diff line change
Expand Up @@ -180,28 +180,34 @@ sub get_config_objects {
# these are obsolete services, just keep them as is
next;
}
my $extra = _get_extra_opts_svc($c, $svc->{'conf'}->{'service_description'}, $hostname, $section);
$settings->{'disabled'} = Thruk::Base::array_remove($settings->{'disabled'}, $id);
$svc->{'conf'} = $chk->{'svc_conf'};
$svc->{'conf'}->{'use'} = \@templates;
delete $chk->{'svc_conf'}->{'_AGENT_ARGS'};
if($args) {
if($args) { # user supplied manual overrides
$chk->{'svc_conf'}->{'_AGENT_ARGS'} = $args;
$chk->{'svc_conf'}->{'check_command'} .= " ".$args;
} else {
# check for default args
$args = _get_default_args($c, $svc->{'conf'}->{'service_description'}, $hostname, $section);
for my $ex (@{$extra}) {
for my $key (sort keys %{$ex}) {
$args = $ex->{$key} if $key eq 'args';
}
}
$chk->{'svc_conf'}->{'check_command'} .= " ".$args if $args;
}
$svc->{'comments'} = ["# autogenerated check: ".$svc->{'conf'}->{'service_description'} ];

# set extra service options
my $extra = _get_extra_opts_svc($c, $svc->{'conf'}->{'service_description'}, $hostname, $section);
for my $ex (@{$extra}) {
for my $key (sort keys %{$ex}) {
next if $key eq 'host';
next if $key eq 'match';
next if $key eq 'section';
next if $key eq 'host_name';
next if $key eq 'args';
$chk->{'svc_conf'}->{$key} = $ex->{$key};
}
}
Expand Down Expand Up @@ -596,6 +602,7 @@ sub _get_extra_opts_svc {
my $res = [];
for my $opt (@{$opts}) {
next unless Thruk::Utils::Agents::check_wildcard_match($name, ($opt->{'match'} // 'ANY'));
next unless Thruk::Utils::Agents::check_wildcard_match($name, ($opt->{'service'} // 'ANY'));
next unless Thruk::Agents::SNClient::check_host_match($opt->{'host'});
next unless Thruk::Utils::Agents::check_wildcard_match($section, ($opt->{'section'} // 'ANY'));
push @{$res}, $opt;
Expand Down

0 comments on commit c17bc44

Please sign in to comment.