Skip to content

Instantly share code, notes, and snippets.

@garthk
Created September 7, 2012 00:09
Show Gist options
  • Select an option

  • Save garthk/3661686 to your computer and use it in GitHub Desktop.

Select an option

Save garthk/3661686 to your computer and use it in GitHub Desktop.
Could not evaluate: undefined method `alias' for #<Nagios::Base::Hostextinfo:0x7fe2d61693b8>
class nagios {
$targets = '/etc/nagios3/puppets.d'
}
class nagios::nrpeclient($binpath) {
include nagios
case $operatingsystem {
'windows': {
$source = $architecture ? {
x64 => "${binpath}\\NSCP-0.4.0.183-x64.msi",
default => "${binpath}\\NSCP-0.4.0.183-Win32.msi",
}
$package = 'nscp'
$service = 'nscp'
$progpath = $architecture ? {
x64 => 'c:/Program Files (x86)/NSClient++',
default => 'c:/Program Files/NSClient++',
}
$inifile = "${progpath}/nsclient.ini"
$inisource = 'puppet:///modules/nagios/nsclient.ini'
}
'Ubuntu': {
$source = undef
$package = 'nagios-nrpe-server'
$service = 'nagios-nrpe-server'
$inifile = '/etc/nagios/nrpe.cfg'
$inisource = 'puppet:///modules/nagios/nrpe.cfg'
}
default: {
fail("unknown operating system: ${operatingsystem}")
}
}
package { $package:
ensure => present,
source => $source,
}
service { $service:
ensure => running,
enable => true,
require => Package[$package],
}
file { $inifile:
ensure => present,
source => $inisource,
require => Package[$package],
notify => Service[$service],
}
# defaults
Nagios_service {
host_name => $::fqdn,
use => 'generic-service',
}
case $operatingsystem {
Ubuntu: {
@@nagios_service { "check_xvda1_${::fqdn}":
check_command => 'check_nrpe_1arg!check_drive_xvda1',
service_description => 'Boot Drive',
target => "${nagios::targets}/host/${::fqdn}.cfg",
}
@@nagios_service { "check_load_${::fqdn}":
check_command => 'check_nrpe_1arg!check_load',
service_description => 'Load',
target => "${nagios::targets}/host/${::fqdn}.cfg",
}
}
windows: {
@@nagios_service { "check_cdrive_${::fqdn}":
check_command => 'check_nrpe!CheckDriveSize!Drive=c MaxWarnUsed=90% MaxCritUsed=95%',
service_description => 'C:',
target => "${nagios::targets}/host/${::fqdn}.cfg",
}
@@nagios_service { "check_cpu_${::fqdn}":
check_command => 'check_nrpe!CheckCPU!warn=80 crit=90 time=1m time=5m time=15m',
service_description => 'CPU',
target => "${nagios::targets}/host/${::fqdn}.cfg",
}
@@nagios_service { "check_ram_${::fqdn}":
check_command => 'check_nrpe!CheckMem!ShowAll type=physical',
service_description => 'RAM',
target => "${nagios::targets}/host/${::fqdn}.cfg",
}
@@nagios_service { "check_swap_${::fqdn}":
check_command => 'check_nrpe!CheckMem!ShowAll type=page',
service_description => 'Swap',
target => "${nagios::targets}/host/${::fqdn}.cfg",
}
}
}
}
class nagios::server {
include nagios
package { 'nagios3':
ensure => installed,
alias => 'nagios',
}
package { ['nagios-plugins-basic', 'nagios-nrpe-plugin']:
ensure => installed,
require => Package['nagios3'],
notify => Service['nagios3'],
}
service { 'nagios3':
ensure => running,
alias => 'nagios',
hasstatus => true,
hasrestart => true,
require => Package[nagios],
}
file { $nagios::targets:
ensure => directory,
owner => 'nagios',
group => 'nagios',
mode => '0755',
require => Package['nagios3'],
}
file { ["${nagios::targets}/command",
"${nagios::targets}/servicegroup",
"${nagios::targets}/host"]:
ensure => directory,
# purge => true,
recurse => true,
owner => 'nagios',
group => 'nagios',
mode => '0644', # puppet will add x for directories
require => Package['nagios3'],
}
file { ['/etc/nagios3/conf.d/services_nagios2.cfg']:
ensure => absent,
notify => Service['nagios3'],
}
file { '/etc/nagios3/nagios.cfg':
ensure => present,
source => ["puppet:///modules/site-nagios/${fqdn}/nagios.cfg",
"puppet:///modules/site-nagios/nagios.cfg",
"puppet:///modules/nagios/nagios.cfg"],
owner => root,
group => root,
mode => '0644',
notify => Service['nagios3'],
}
exec { 'fixperms':
cwd => $nagios::targets,
path => '/bin',
command => "chmod -R a+rX .",
notify => Service['nagios3'],
}
# collect resources and populate /etc/nagios/nagios_*.cfg
Nagios_command <<||>> {
# notify => Exec['fixperms'],
}
Nagios_host <<||>> {
# notify => Exec['fixperms'],
}
Nagios_service <<||>> {
# notify => Exec['fixperms'],
}
Nagios_servicegroup <<||>> {
# notify => Exec['fixperms'],
}
Nagios_hostextinfo <<||>> {
# notify => Exec['fixperms'],
}
@@nagios_servicegroup { 'nagios':
# alias => 'nagios',
target => "${nagios::targets}/servicegroup/nagios.cfg",
}
@@nagios_command { 'check_http_name_auth':
command_line => '/usr/lib/nagios/plugins/check_http -H $ARG1$ -I $HOSTADDRESS$ -e \'HTTP/1.1 401\'',
target => "${nagios::targets}/command/check_http_name_auth.cfg",
}
@@nagios_service { 'check_nagios3_${::fqdn}':
service_description => 'Nagios3 Web',
check_command => "check_http_name_auth!${::fqdn}",
host_name => $::fqdn,
use => 'generic-service',
servicegroups => 'nagios',
target => "${nagios::targets}/host/${::fqdn}.cfg",
}
}
class nagios::target {
include nagios
@@nagios_host { $::fqdn:
ensure => present,
alias => $::hostname,
address => $::ipaddress,
use => "generic-host",
check_command => 'check-host-alive!3000.0,80%!5000.0,100%!10',
target => "${nagios::targets}/host/${::fqdn}.cfg",
}
@@nagios_hostextinfo { $::fqdn:
ensure => present,
icon_image_alt => $operatingsystem,
icon_image => "base/$operatingsystem.png",
statusmap_image => "base/$operatingsystem.gd2",
target => "${nagios::targets}/host/${::fqdn}.cfg",
}
@@nagios_service { "check_ping_${::fqdn}":
check_command => 'check_ping!100.0,20%!500.0,60%',
host_name => $::fqdn,
service_description => 'Ping',
use => "generic-service",
target => "${nagios::targets}/host/${::fqdn}.cfg",
}
if $operatingsystem != 'windows' {
@@nagios_service { "check_ssh_${::fqdn}":
check_command => 'check_ssh_port!22',
host_name => $::fqdn,
service_description => "SSH",
use => "generic-service",
target => "${nagios::targets}/host/${::fqdn}.cfg",
}
}
}
@garthk

garthk commented Sep 7, 2012

Copy link
Copy Markdown
Author

Error: Could not evaluate: undefined methodalias' for #Nagios::Base::Hostextinfo:0x7fe2d61693b8`

Solution: rm -rf /etc/nagios3/puppets.d #wtf

@garthk

garthk commented Sep 7, 2012

Copy link
Copy Markdown
Author

Problem somehow addressed by removing all Puppet-generated .cfg files and re-running Puppet.

@garthk

garthk commented Oct 9, 2012

Copy link
Copy Markdown
Author

… except that it's back, in a fashion: on the first run Puppet will create the .cfg files but leave out some vital define host entries. On the second run Puppet will fail with the undefined method error above.

@stevedwray

Copy link
Copy Markdown

Did you ever get to the bottom of this? Because I'm having the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment