Issues for Nagios - KeegMitch/Operations-Engineering-group-c GitHub Wiki

Problems

Attempting different service.pp codes

image

From what i can tell it might be a problem with the difference between nagios and nagios3 because of this image

Latest error.

image

This is the current service.pp

image

This is the current config.pp

image

Current config is messing up the puppet agent, now the service isn't running:

image

Problem with config.pp in how it's creating ppt_hosts.cfg

Code being used is from the Nagios Puppet Module page.

Error when testing the puppet agent:

image

It does appear to create the file, but it appears to be complaining about the syntax?

image

Update, I got rid of just the host_alias part of the config.pp code and now it comes up with this error:

image

Now trying a different approach to the nagios_host resource type by figuring out how to implement nagios_core stuff into Puppet version 6.2, as the resource types moved there , source: https://forge.puppet.com/modules/puppetlabs/nagios_core/reference#nagios_host

Solutions attempted

This is in regard to the service.pp file:

image

Looks like the system nagios3 is running? sudo systemctl status nagios3

Fixed the service name in service.pp:

image

Now we're not getting that error

image

Testing the config.pp stage

Added this:

image

Got this error, which relates to the exec code:

image

Changed it to this code:

image

Error:

image

Modified the code to just using the -c flag :

image

Now I get this when testing it:

image

I got rid of the files part of the path here:

image

Now I get no errors:

image

Setting up nagios host:

image

I get this error:

image

Resolving the nagios_hosts error

Create a template in the templates folder (this di not work):

sudo touch ppt_hosts.cfg.erb

image

add this code:

define host {
  host_name  <%= @hostname %>
  alias       <%= @alias %>
  check_period  <%= @check_period %>
  max_check_attempts <%= @max_check_attempts %>
  check_command  <%= @check_command %>
  notification_interval <%= @notification_interval %>
  notification_period <%= @notification_period %>
  notification_options <%= @notification_options %>
  mode      <%= @mode %>
}

image

template { "/etc/nagios3/conf.d/ppt_hosts.cfg":
  source => "templates/ppt_hosts.cfg.erb",
  owner  => "nagios",
  group  => "nagios",
  mode   => "0444",
  variables => {
    hostname       => "db-c.foo.org.nz",
    alias           => "db",
    check_period   => "24x7",
    max_check_attempts => 3,
    check_command  => "check-host-alive",
    notification_interval => 30,
    notification_period => "24x7",
    notification_options => "d,u,r",
  }
}

image

This solution below worked:

including this code in the config.pp for nagios host:

# Define the nagios_host resource to monitor the status of the database server
  define nagios_host (
    $target,
    $host_alias,
    $check_period,
    $max_check_attempts,
    $check_command,
    $notification_interval,
    $notification_period,
    $notification_options,
    $mode,
  ) {
    file { "/etc/nagios3/conf.d/ppt_hosts.cfg":
      ensure  => present,
      content => "
define host {
  use                     linux-server
  host_name               ${title}
  alias                   ${host_alias}
  address                 ${target}
  check_period            ${check_period}
  max_check_attempts      ${max_check_attempts}
  check_command           ${check_command}
  notification_interval   ${notification_interval}
  notification_period     ${notification_period}
  notification_options    ${notification_options}
}
",
      mode    => $mode,
      require => File['/etc/nagios3/conf.d'],
    }
  }

  # Use the custom nagios_host resource type to define the Nagios host
  nagios::config::nagios_host { "db-c.foo.org.nz":
    target                => "db-c.foo.org.nz",
    host_alias            => "db",
    check_period          => "24x7",
    max_check_attempts    => 3,
    check_command         => "check-host-alive",
    notification_interval => 30,
    notification_period   => "24x7",
    notification_options  => "d,u,r",
    mode                  => "0444",
  }

Testing:

image

Issues with login to Nagios web server

With the current confg.pp file, There is most likely an issue with how the htpasswd is configured.

At this stage we can connect to the nagios web server, but it prompts a login, however the login for nagiosadmin doesnt work even when trying to change the password:

image

image

The issue looks like it's to do with when testing the puppet agent, it doesn't prompt for a password when i use the specific command from the lab, so it's to do with the htpasswd file

Adding to the config to address config error

adding this to config.pp

# Ensure the resource.cfg file exists
  file { '/etc/nagios3/resource.cfg':
    ensure  => present,
    content => '',  # You can leave it empty or add specific configurations if needed
    mode    => '0644',
    require => Class['nagios::install'],
    notify  => Class['nagios::service'],
  }

  # Ensure the commands.cfg file exists
  file { '/etc/nagios3/commands.cfg':
    ensure  => present,
    content => '',  # You can leave it empty or add specific configurations if needed
    mode    => '0644',
    require => Class['nagios::install'],
    notify  => Class['nagios::service'],
  }

changed the target path at the end to this:

nagios::config::nagios_host { "db-c.foo.org.nz":
  target                => "/etc/nagios3/conf.d/ppt_hosts.cfg",
  alias                 => "db",
  check_period          => "24x7",
  max_check_attempts    => 3,
  check_command         => "check-host-alive",
  notification_interval => 30,
  notification_period   => "24x7",
  notification_options  => "d,u,r",
  mode                  => "0444",
}

Now getting this error:

image

Removing some problematic files that were created with the config.pp file:

image

Current error:

image

At this point I know it's the config.pp code, but I cannot pinpoint without making more errors

Attempt to add define service to config.pp

class nagios::config {

# File resource that manages the nagios config file
  file { "/etc/nagios3/nagios.cfg":
    ensure  => present,
    source  => "puppet:///modules/nagios/nagios.cfg",
    mode    => "0644",
    require => Class["nagios::install"],
    notify  => Class["nagios::service"],
  }

# File resource to manage usernames and passwords (causing problems)

exec { "create-htpasswd":
    command => "/usr/bin/htpasswd  -c /etc/puppetlabs/code/modules/nagios/files/htpasswd.users nagiosadmin",
    creates => "/etc/puppetlabs/code/modules/nagios/files/htpasswd.users",
    require => Class["nagios::install"],
    notify  => Class["nagios::service"],
    path    => '/bin:/sbin:/usr/bin:/usr/sbin',

  }

  file { "/etc/nagios3/htpasswd.users":
    ensure  => present,
    source  => "puppet:///modules/nagios/htpasswd.users",
    mode    => "0600",
    owner   => "nagios",
    group   => "nagios",
    require => Exec["create-htpasswd"],
    notify  => Class["nagios::service"],
  }

# File resource that ensures the /etc/nagios3/conf.d directory is present, sets its group ownership to puppet, and its mode to 0775

file { "/etc/nagios3/conf.d":
    ensure  => directory,
    mode    => "0775",
    owner   => "root",
    group   => "puppet",
    require => Class["nagios::install"],
  }

# Define the nagios_host resource to monitor the status of the database server

 define nagios_host (
    $target,
    $host_alias,
    $check_period,
    $max_check_attempts,
    $check_command,
    $notification_interval,
    $notification_period,
    $notification_options,
    $mode,
    $prefix = "ppt_"
  ) {
    file { "/etc/nagios3/conf.d/${prefix}hosts.cfg":
      ensure  => present,
      content => "
define host {
  host_name               ${title}
  host_alias              ${host_alias}
  address                 ${target}
  check_period            ${check_period}
  max_check_attempts      ${max_check_attempts}
  check_command           ${check_command}
  notification_interval   ${notification_interval}
  notification_period     ${notification_period}
  notification_options    ${notification_options}
}
",
      mode    => $mode,
      require => File['/etc/nagios3/conf.d'],
    }
  }

  # Use the custom nagios_host resource type to define the Nagios host
  nagios::config::nagios_host { "db-c.foo.org.nz":
    target                => "db-c.foo.org.nz",
    host_alias            => "db",
    check_period          => "24x7",
    max_check_attempts    => 3,
    check_command         => "check-host-alive",
    notification_interval => 30,
    notification_period   => "24x7",
    notification_options  => "d,u,r",
    mode                  => "0444",
  }

}

class nagios::services {
# Define the service for NTP outside the class
define service {
  use                     generic-service
  host_name               db-c.foo.org.nz
  service_description     NTP
  check_command           check_ntp_time!-H
  max_check_attempts      3
  check_interval          5
  retry_interval          1
  check_period            "24x7"
  notification_interval   30
  notification_period     "24x7"
  notification_options    "w,u,c,r"
}
}

Have been getting theses errors from it.

image

Updated service



  # Define the nagios_service resource to monitor services
  define nagios_service (
    $host_name,
    $service_description,
    $check_command,
    $max_check_attempts,
    $check_interval,
    $retry_interval,
    $check_period,
    $notification_interval,
    $notification_period,
    $notification_options,
    $mode,
    $prefix = "ppt_"
  ) {
    file { "/etc/nagios3/conf.d/${prefix}services.cfg":
      ensure  => present,
      content => "
define service {
  use                     generic-service
  host_name               ${host_name}
  service_description     ${service_description}
  check_command           ${check_command}
  max_check_attempts      ${max_check_attempts}
  check_interval          ${check_interval}
  retry_interval          ${retry_interval}
  check_period            ${check_period}
  notification_interval   ${notification_interval}
  notification_period     ${notification_period}
  notification_options    ${notification_options}
}
",
      mode    => $mode,
      require => File['/etc/nagios3/conf.d'],
    }
  }

  # Use the custom nagios_host resource type to define the Nagios host
  nagios::config::nagios_host { "db-c.foo.org.nz":
    target                => "db-c.foo.org.nz",
    host_alias            => "db",
    check_period          => "24x7",
    max_check_attempts    => 3,
    check_command         => "check-host-alive",
    notification_interval => 30,
    notification_period   => "24x7",
    notification_options  => "d,u,r",
    mode                  => "0444",
  }

}

  # Use the custom nagios_service resource type to define Nagios services
  nagios_service { "ntp-check":
    host_name               => "db-c.foo.org.nz",
    service_description     => "NTP",
    check_command           => "check_ntp_time!-H",
    max_check_attempts      => 3,
    check_interval          => 5,
    retry_interval          => 1,
    check_period            => "24x7",
    notification_interval   => 30,
    notification_period     => "24x7",
    notification_options    => "w,u,c,r",
    mode                    => "0444",
  }


class nagios::services {
}

image

⚠️ **GitHub.com Fallback** ⚠️