Skip to content

Commit

Permalink
Merge d18be80 into e1007e2
Browse files Browse the repository at this point in the history
  • Loading branch information
peternewman committed Feb 12, 2019
2 parents e1007e2 + d18be80 commit e17eb1e
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 50 deletions.
2 changes: 1 addition & 1 deletion t/nagios2config.t
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ok( scalar(@$svc_members) == 3, "Servicegroup1 should have 3 members" );
$msg . " index 0 was not a Nagios::Host"
);
ok( ref( $element->[1] ) eq 'Nagios::Service',
$msg . " index 1 was not a Nagios::Host"
$msg . " index 1 was not a Nagios::Service"
);
}

Expand Down
43 changes: 19 additions & 24 deletions t/nagios3config.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use Test::NoWarnings;

use lib qw( ./lib ../lib );

BEGIN { plan tests => 25; }
BEGIN { plan tests => 17; }
eval { chdir('t') };

use_ok('Nagios::Config');

ok( my $cf = Nagios::Config->new(
Filename => "v2_config/nagios.cfg",
Version => 2
Filename => "v3_config/nagios.cfg",
Version => 3
),
"Nagios::Config->new()"
);
Expand Down Expand Up @@ -47,40 +47,35 @@ ok( $cf->register_objects,
ok( my @hosts = $cf->list_hosts(), "\$parser->list_hosts()" );
ok( my @services = $cf->list_hosts(), "\$parser->list_services()" );

ok( my @hostgroups = $cf->list_hostgroups(), "\$parser->list_hostgroups()" );
my @hostgroups = $cf->list_hostgroups();
ok( @hostgroups, "\$parser->list_hostgroups()" );

my @servicegroups = $cf->list_servicegroups();
ok( @servicegroups, "\$parser->list_servicegroups()" );

# diag ("service groups: " . join(', ', map { $_->servicegroup_name } @servicegroups));
my $svcgroup1
= ( grep { $_->servicegroup_name eq 'svcgroup1' } @servicegroups )[0];
# diag ("host groups: " . join(', ', map { $_->hostgroup_name } @hostgroups));
my $linux_servers
= ( grep { $_->hostgroup_name eq 'linux-servers' } @hostgroups )[0];

ok( defined($svcgroup1), "Found servicegroup1 in configuration" );
ok( defined($linux_servers), "Found linux-servers in configuration" );

# make sure svcgroup1 has 3 members, each of which is a host/service pair
# make sure linux-servers has 1 members, which is a host

my $svc_members = $svcgroup1->members();
ok( scalar(@$svc_members) == 3, "Servicegroup1 should have 3 members" );
my $host_members = $linux_servers->members();
ok( scalar(@$host_members) == 1, "linux-servers should have 1 member" );

# diag ("svcgroup1 members: " . join(', ', map { "[" . join(", ", @{$_} ) . "]" } @$svc_members));
# diag ("linux-servers members: " . join(', ', map { "[" . join(", ", @{$_} ) . "]" } @$host_members));

{

sub checkelement {
my $element = shift;
my $msg = shift;

ok( scalar(@$element) == 2, $msg . " did not have 2 entries" );
ok( ref( $element->[0] ) eq 'Nagios::Host',
$msg . " index 0 was not a Nagios::Host"
);
ok( ref( $element->[1] ) eq 'Nagios::Service',
$msg . " index 1 was not a Nagios::Host"
ok( ref( $element ) eq 'Nagios::Host',
$msg . " was not a Nagios::Host"
);
}

checkelement( $svc_members->[0], "Servicegroup1 first entry" );
checkelement( $svc_members->[1], "Servicegroup1 second entry" );
checkelement( $svc_members->[2], "Servicegroup1 third entry" );
checkelement( $host_members->[0], "linux-servers first entry" );
}

my @servicegroups = $cf->list_servicegroups();
ok( scalar(@servicegroups) == 0, "\$parser->list_servicegroups()" );
11 changes: 9 additions & 2 deletions t/v3_config/cgi.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#################################################################
#
# CGI.CFG - Sample CGI Configuration File for Nagios 3.1.2
# CGI.CFG - Sample CGI Configuration File for Nagios 3.5.1
#
# Last Modified: 06-17-2009
#
Expand All @@ -12,7 +12,7 @@
# The CGIs will read the main and host config files for any other
# data they might need.

main_config_file=/usr/local/nagios/etc/nagios.cfg
main_config_file=v3_config/nagios.cfg



Expand Down Expand Up @@ -274,6 +274,13 @@ ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$

refresh_rate=90

# DEFAULT PAGE LIMIT
# This option allows you to specify the default number of results
# displayed on the status.cgi. This number can be adjusted from
# within the UI after the initial page load. Setting this to 0
# will show all results.

result_limit=100


# ESCAPE HTML TAGS
Expand Down
7 changes: 7 additions & 0 deletions t/v3_config/cgi.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$

refresh_rate=90

# DEFAULT PAGE LIMIT
# This option allows you to specify the default number of results
# displayed on the status.cgi. This number can be adjusted from
# within the UI after the initial page load. Setting this to 0
# will show all results.

result_limit=100


# ESCAPE HTML TAGS
Expand Down
2 changes: 1 addition & 1 deletion t/v3_config/mrtg.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###################################################################
# MRTG Graphs: Nagios 3.1.2 Statistics
# MRTG Graphs: Nagios 3.5.1 Statistics
#
# You can add the following entries to your MRTG config file to
# begin graphing several Nagios statistics which can be useful for
Expand Down
58 changes: 43 additions & 15 deletions t/v3_config/nagios.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##############################################################################
#
# NAGIOS.CFG - Sample Main Config File for Nagios 3.1.2
# NAGIOS.CFG - Sample Main Config File for Nagios 3.5.1
#
# Read the documentation for more information on this configuration
# file. I've provided some comments here, but things may not be so
Expand All @@ -27,32 +27,32 @@ log_file=/usr/local/nagios/var/nagios.log
# if you wish (as shown below), or keep them all in a single config file.

# You can specify individual object config files as shown below:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=v3_config/template-object/commands.cfg
cfg_file=v3_config/template-object/contacts.cfg
cfg_file=v3_config/template-object/timeperiods.cfg
cfg_file=v3_config/template-object/templates.cfg

# Definitions for monitoring the local (Linux) host
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_file=v3_config/template-object/localhost.cfg

# Definitions for monitoring a Windows machine
#cfg_file=/usr/local/nagios/etc/objects/windows.cfg
#cfg_file=v3_config/template-object/windows.cfg

# Definitions for monitoring a router/switch
#cfg_file=/usr/local/nagios/etc/objects/switch.cfg
#cfg_file=v3_config/template-object/switch.cfg

# Definitions for monitoring a network printer
#cfg_file=/usr/local/nagios/etc/objects/printer.cfg
#cfg_file=v3_config/template-object/printer.cfg


# You can also tell Nagios to process all config files (with a .cfg
# extension) in a particular directory by using the cfg_dir
# directive as shown below:

#cfg_dir=/usr/local/nagios/etc/servers
#cfg_dir=/usr/local/nagios/etc/printers
#cfg_dir=/usr/local/nagios/etc/switches
#cfg_dir=/usr/local/nagios/etc/routers
#cfg_dir=v3_config/servers
#cfg_dir=v3_config/printers
#cfg_dir=v3_config/switches
#cfg_dir=v3_config/routers



Expand Down Expand Up @@ -93,7 +93,7 @@ precached_object_file=/usr/local/nagios/var/objects.precache
# defined as macros in this file and restrictive permissions (600)
# can be placed on this file.

resource_file=/usr/local/nagios/etc/resource.cfg
resource_file=v3_config/resource.cfg



Expand Down Expand Up @@ -634,7 +634,7 @@ retain_state_information=1
# service state information before it shuts down. The state
# information in this file is also read immediately prior to
# starting to monitor the network when Nagios is restarted.
# This file is used only if the preserve_state_information
# This file is used only if the retain_state_information
# variable is set to 1.

state_retention_file=/usr/local/nagios/var/retention.dat
Expand Down Expand Up @@ -901,6 +901,18 @@ process_performance_data=0



# HOST AND SERVICE PERFORMANCE DATA PROCESS EMPTY RESULTS
# THese options determine wether the core will process empty perfdata
# results or not. This is needed for distributed monitoring, and intentionally
# turned on by default.
# If you don't require empty perfdata - saving some cpu cycles
# on unwanted macro calculation - you can turn that off. Be careful!
# Values: 1 = enable, 0 = disable

#host_perfdata_process_empty_results=1
#service_perfdata_process_empty_results=1


# OBSESS OVER SERVICE CHECKS OPTION
# This determines whether or not Nagios will obsess over service
# checks and run the ocsp_command defined below. Unless you're
Expand Down Expand Up @@ -1016,6 +1028,22 @@ service_freshness_check_interval=60



# SERVICE CHECK TIMEOUT STATE
# This setting determines the state Nagios will report when a
# service check times out - that is does not respond within
# service_check_timeout seconds. This can be useful if a
# machine is running at too high a load and you do not want
# to consider a failed service check to be critical (the default).
# Valid settings are:
# c - Critical (default)
# u - Unknown
# w - Warning
# o - OK

service_check_timeout_state=c



# HOST FRESHNESS CHECK OPTION
# This option determines whether or not Nagios will periodically
# check the "freshness" of host results. Enabling this option
Expand Down
30 changes: 29 additions & 1 deletion t/v3_config/nagios.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ retain_state_information=1
# service state information before it shuts down. The state
# information in this file is also read immediately prior to
# starting to monitor the network when Nagios is restarted.
# This file is used only if the preserve_state_information
# This file is used only if the retain_state_information
# variable is set to 1.

state_retention_file=@localstatedir@/retention.dat
Expand Down Expand Up @@ -901,6 +901,18 @@ process_performance_data=0



# HOST AND SERVICE PERFORMANCE DATA PROCESS EMPTY RESULTS
# THese options determine wether the core will process empty perfdata
# results or not. This is needed for distributed monitoring, and intentionally
# turned on by default.
# If you don't require empty perfdata - saving some cpu cycles
# on unwanted macro calculation - you can turn that off. Be careful!
# Values: 1 = enable, 0 = disable

#host_perfdata_process_empty_results=1
#service_perfdata_process_empty_results=1


# OBSESS OVER SERVICE CHECKS OPTION
# This determines whether or not Nagios will obsess over service
# checks and run the ocsp_command defined below. Unless you're
Expand Down Expand Up @@ -1016,6 +1028,22 @@ service_freshness_check_interval=60



# SERVICE CHECK TIMEOUT STATE
# This setting determines the state Nagios will report when a
# service check times out - that is does not respond within
# service_check_timeout seconds. This can be useful if a
# machine is running at too high a load and you do not want
# to consider a failed service check to be critical (the default).
# Valid settings are:
# c - Critical (default)
# u - Unknown
# w - Warning
# o - OK

service_check_timeout_state=c



# HOST FRESHNESS CHECK OPTION
# This option determines whether or not Nagios will periodically
# check the "freshness" of host results. Enabling this option
Expand Down
2 changes: 1 addition & 1 deletion t/v3_config/resource.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
###########################################################################
#
# RESOURCE.CFG - Sample Resource File for Nagios 3.1.2
# RESOURCE.CFG - Sample Resource File for Nagios 3.5.1
#
# Last Modified: 09-10-2003
#
Expand Down
4 changes: 2 additions & 2 deletions t/v3_config/template-object/commands.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# COMMANDS.CFG - SAMPLE COMMAND DEFINITIONS FOR NAGIOS 3.1.2
# COMMANDS.CFG - SAMPLE COMMAND DEFINITIONS FOR NAGIOS 3.5.1
#
# Last Modified: 05-31-2007
#
Expand Down Expand Up @@ -33,7 +33,7 @@ define command{
# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}


Expand Down
2 changes: 1 addition & 1 deletion t/v3_config/template-object/commands.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ define command{
# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | @MAIL_PROG@ -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | @MAIL_PROG@ -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}


Expand Down
2 changes: 1 addition & 1 deletion t/v3_config/template-object/timeperiods.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ define timeperiod{
monday -1 may 00:00-00:00 ; Memorial Day (last Monday in May)
july 4 00:00-00:00 ; Independence Day
monday 1 september 00:00-00:00 ; Labor Day (first Monday in September)
thursday -1 november 00:00-00:00 ; Thanksgiving (last Thursday in November)
thursday 4 november 00:00-00:00 ; Thanksgiving (4th Thursday in November)
december 25 00:00-00:00 ; Christmas
}

Expand Down
2 changes: 1 addition & 1 deletion t/v3_config/template-object/timeperiods.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ define timeperiod{
monday -1 may 00:00-00:00 ; Memorial Day (last Monday in May)
july 4 00:00-00:00 ; Independence Day
monday 1 september 00:00-00:00 ; Labor Day (first Monday in September)
thursday -1 november 00:00-00:00 ; Thanksgiving (last Thursday in November)
thursday 4 november 00:00-00:00 ; Thanksgiving (4th Thursday in November)
december 25 00:00-00:00 ; Christmas
}

Expand Down

0 comments on commit e17eb1e

Please sign in to comment.