Open raiblue opened 9 years ago
Hi again, I worked out this problem by creating a command.pp (like service.pp) as follows:
define nagios::command ( $ensure = undef, $server = $nagios::client::server, $host_name = $nagios::client::host_name, $nrpe = "\$USER1\$/check_nrpe -H \$HOSTADDRESS\$", $command_line, ) {
@@nagios_command { $title: command_line => $command_line, tag => regsubst($server,'^(.+)$','nagios-\1'), } }
After that, i could be able to use it in my tcp check manifest:
define nagios::check::tcp ( $ensure = undef, $nrpe = "\$USER1\$/check_nrpe -H \$HOSTADDRESS\$", $args, ) {
if $ensure != 'absent' { Package <| tag == 'nagios-plugins-tcp' |> }
nagios::client::nrpe_file { "checktcp${title}": ensure => $ensure, args => $args, plugin => 'check_tcp', }
nagios::service { "checktcp${title}_${::nagios::client::host_name}": ensure => $ensure, check_command => "check_nrpetcp${title}", service_description => "${title}", servicegroups => $servicegroups, check_period => $check_period, contact_groups => $contact_groups, first_notification_delay => $first_notification_delay, notification_period => $notification_period, max_check_attempts => $max_check_attempts, use => $use, }
nagios::command { "check_nrpetcp${title}": ensure => $ensure, command_line => "${nrpe} -c checktcp${title}", } }
And calling them as usual:
nagios::check::tcp { 'nexus': args => hiera(nagios::check::nexus::args,"-p 8081"), } nagios::check::tcp { 'sonar': args => hiera(nagios::check::sonar::args,"-p 9002"), }
No need to write them in server.pp, my custom commands are created based on titles and exported to nagios_commands.cfg directly :)
I wonder why something like command.pp is not included in the module. It would provide convenience.
Hi, I'm trying to add new checks. My definitions (for example that manifests/check/tcp.pp below) work good:
define nagios::check::tcp ( $ensure = undef, $args, ) {
Required plugin
if $ensure != 'absent' { Package <| tag == 'nagios-plugins-tcp' |> }
nagios::client::nrpe_file { "checktcp${title}": ensure => $ensure, args => $args, plugin => "check_tcp", }
nagios::service { "checktcp${title}_${::nagios::client::host_name}": ensure => $ensure, check_command => "check_nrpetcp${title}", service_description => "${title}", servicegroups => $servicegroups, check_period => $check_period, contact_groups => $contact_groups, first_notification_delay => $first_notification_delay, notification_period => $notification_period, max_check_attempts => $max_check_attempts, use => $use, } }
And I call that definition like that:
nagios::check::tcp { 'sonar': args => hiera(nagios::check::sonar::args,"-p 9002"), }
No problem up to here: Nrpe check is created on the client side and service definition is created on the server side as expected. My problem is, I have to add the command definition to manifests/server.pp manually to get it created on server side:
nagios_command { 'check_nrpe_tcp_sonar': command_line => "${nrpe} -c check_tcp_sonar", }
How can I do it from check manifest (manifests/check/tcp.pp) automaticaly? I tried nagios_command and @@nagios_command but i couldn't do what I need. I need something like nagios::service. Is it also supported in module? Could somebody help?