Error: Template 'linux-server' specified in host definition

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
DBish
Posts: 5
Joined: Thu Oct 25, 2018 11:00 am

Error: Template 'linux-server' specified in host definition

Post by DBish »

Hi All

Nagios Core (nagios3) on Ubuntu 16.04

I'm a bit new to Nagios - dabbled a little but still just learning.

I've got a problem with Nagios core whereby I cannot make changes to the nagios.cfg file and restart the service without errors. With no changes I have the local host monitored as you'd expect from default.

After a few attempts at troubleshooting I am at the stage where I've hit a wall. journalctl -xe seems to suggest that the 'Linux-Server' Template is missing. Where would this normally be stored and how could I reinstall it without reinstalling Nagios.

Thanks


Here is the end snippet from : journalctl -xe

Oct 25 16:00:31 nagios3[24351]: Processing object config file '/etc/nagios3/conf.d/hostgroups_nagios2.cfg'...
Oct 25 16:00:31 nagios3[24351]: Processing object config file '/etc/nagios3/objects/servers.cfg'...
Oct 25 16:00:31 i nagios3[24351]: Error: Template 'linux-server' specified in host definition could not be not found (config file '/etc/nagios3/objects/servers.cfg', starting on line 40)
Oct 25 16:00:31 nagios3[24351]: Error processing object config files!
Oct 25 16:00:31 nagios3[24351]: ***> One or more problems was encountered while processing the config files...
Oct 25 16:00:31 nagios3[24351]: Check your configuration file(s) to ensure that they contain valid
Oct 25 16:00:31 nagios3[24351]: directives and data defintions. If you are upgrading from a previous
Oct 25 16:00:31 nagios3[24351]: version of Nagios, you should be aware that some variables/definitions
Oct 25 16:00:31 systemd[1]: nagios3.service: Control process exited, code=exited status=1
Oct 25 16:00:31 nagios3[24351]: may have been removed or modified in this version. Make sure to read
Oct 25 16:00:31 nagios3[24351]: the HTML documentation regarding the config files, as well as the
Oct 25 16:00:31 nagios3[24351]: 'Whats New' section to find out what has changed.
Oct 25 16:00:31 systemd[1]: Failed to start LSB: nagios host/service/network monitoring and management system.
-- Subject: Unit nagios3.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/li ... temd-devel
--
-- Unit nagios3.service has failed.
--
-- The result is failed.
Oct 25 16:00:31 nagios3[24351]: * errors in config!
Oct 25 16:00:31 nagios3[24351]: ...fail!
Oct 25 16:00:31 sudo[24345]: pam_unix(sudo:session): session closed for user root
Oct 25 16:00:31 systemd[1]: nagios3.service: Unit entered failed state.
Oct 25 16:00:31 systemd[1]: nagios3.service: Failed with result 'exit-code'.
DBish
Posts: 5
Joined: Thu Oct 25, 2018 11:00 am

Re: Error: Template 'linux-server' specified in host definit

Post by DBish »

Ok, so I noticed that the templates file was commented out in the nagios.cfg file, but now I have another issue. When I uncomment the line for the template.cfg and restart the service I still get a failure code - see below

nagios3[31082]: Processing object config file '/etc/nagios3/objects/templates.cfg'...
nagios3[31082]: Warning: Duplicate definition found for host 'generic-host' (config file '/etc/nagios3/objects/templates.cfg'
nagios3[31082]: Error: Could not add object property in file '/etc/nagios3/objects/templates.cfg' on line 53.
nagios3[31082]: Error processing object config files!
nagios3[31082]: ***> One or more problems was encountered while processing the config files...
nagios3[31082]: Check your configuration file(s) to ensure that they contain valid
nagios3[31082]: directives and data defintions. If you are upgrading from a previous
systemd[1]: nagios3.service: Control process exited, code=exited status=1
sudo[31076]: pam_unix(sudo:session): session closed for user root
nagios3[31082]: version of Nagios, you should be aware that some variables/definitions
nagios3[31082]: may have been removed or modified in this version. Make sure to read
nagios3[31082]: the HTML documentation regarding the config files, as well as the
nagios3[31082]: 'Whats New' section to find out what has changed.
systemd[1]: Failed to start LSB: nagios host/service/network monitoring and management system.
-- Subject: Unit nagios3.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/li ... temd-devel
--
-- Unit nagios3.service has failed.
--
-- The result is failed.
nagios3[31082]: * errors in config!
nagios3[31082]: ...fail!
systemd[1]: nagios3.service: Unit entered failed state.
npolovenko
Support Tech
Posts: 3457
Joined: Mon May 15, 2017 5:00 pm

Re: Error: Template 'linux-server' specified in host definit

Post by npolovenko »

@DBish, Have you upgraded this Nagios Core server recently or imported configs from somewhere else? I suggest looking at the line 53 of the templates.cfg file. If you can't find anything outstanding please upload the file here so I could take a look.
'/etc/nagios3/objects/templates.cfg'
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
DBish
Posts: 5
Joined: Thu Oct 25, 2018 11:00 am

Re: Error: Template 'linux-server' specified in host definit

Post by DBish »

Whenever I uncomment the template.cfg line in the nagios.cfg file and restart the service I'm told there is a duplicate
Warning: Duplicate definition found for host 'generic-host' (config file '/etc/nagios3/objects/templates.cfg', starting on line 52)
nagios3[12053]: Error: Could not add object property in file '/etc/nagios3/objects/templates.cfg' on line 53

If I recomment the template.cfg line and only have my device line uncommented e.g. pointed at a file called switch.cfg then it tells me that the template 'generic-switch' is missing.
Error: Template 'generic-switch' specified in host definition could not be not found (config file '/etc/nagios3/objects/switch.cfg', st

So it seems like there must be a pointer somewhere to a different templates file, but if that were the case I could understand the duplicate error, but why wouldn't the 'generic-switch' template/config then be found
DBish
Posts: 5
Joined: Thu Oct 25, 2018 11:00 am

Re: Error: Template 'linux-server' specified in host definit

Post by DBish »

Here is the templates file - it is generic and hasn't been edited - so perhaps a bug of some sort has been introduced when I did an update (sudo - apt-get update)

###############################################################################
# TEMPLATES.CFG - SAMPLE OBJECT TEMPLATES
#
# Last Modified: 10-03-2007
#
# NOTES: This config file provides you with some example object definition
# templates that are refered by other host, service, contact, etc.
# definitions in other config files.
#
# You don't need to keep these definitions in a separate file from your
# other object definitions. This has been done just to make things
# easier to understand.
#
###############################################################################



###############################################################################
###############################################################################
#
# CONTACT TEMPLATES
#
###############################################################################
###############################################################################

# Generic contact definition template - This is NOT a real contact, just a template!

define contact{
name generic-contact ; The name of this contact template
service_notification_period 24x7 ; service notifications can be sent anytime
host_notification_period 24x7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
service_notification_commands notify-service-by-email ; send service notifications via email
host_notification_commands notify-host-by-email ; send host notifications via email
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}




###############################################################################
###############################################################################
#
# HOST TEMPLATES
#
###############################################################################
###############################################################################

# Generic host definition template - This is NOT a real host, just a template!

define host{
name generic-host ; The name of this host template
notifications_enabled 1 ; Host notifications are enabled
event_handler_enabled 1 ; Host event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
notification_period 24x7 ; Send host notifications at any time
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
}

# Linux host definition template - This is NOT a real host, just a template!

define host{
name linux-server ; The name of this host template
use generic-host ; This template inherits other values from the generic-host template
check_period 24x7 ; By default, Linux hosts are checked round the clock
check_interval 5 ; Actively check the host every 5 minutes
retry_interval 1 ; Schedule host check retries at 1 minute intervals
max_check_attempts 3 ; Check each Linux host 10 times (max)
check_command check-host-alive ; Default command to check Linux hosts
notification_period workhours ; Linux admins hate to be woken up, so we only notify during the day
; Note that the notification_period variable is being overridden from
; the value that is inherited from the generic-host template!
notification_interval 60 ; Resend notifications every 2 hours
notification_options d,u,r ; Only send notifications for specific host states
contact_groups admins ; Notifications get sent to the admins by default
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
}



# Windows host definition template - This is NOT a real host, just a template!

define host{
name windows-server ; The name of this host template
use generic-host ; Inherit default values from the generic-host template
check_period 24x7 ; By default, Windows servers are monitored round the clock
check_interval 5 ; Actively check the server every 5 minutes
retry_interval 1 ; Schedule host check retries at 1 minute intervals
max_check_attempts 3 ; Check each server 10 times (max)
check_command check-host-alive ; Default command to check if servers are "alive"
notification_period 24x7 ; Send notification out at any time - day or night
notification_interval 60 ; Resend notifications every 30 minutes
notification_options d,r ; Only send notifications for specific host states
contact_groups admins ; Notifications get sent to the admins by default
hostgroups windows-servers ; Host groups that Windows servers should be a member of
register 0 ; DONT REGISTER THIS - ITS JUST A TEMPLATE
}


# We define a generic printer template that can be used for most printers we monitor

define host{
name generic-printer ; The name of this host template
use generic-host ; Inherit default values from the generic-host template
check_period 24x7 ; By default, printers are monitored round the clock
check_interval 5 ; Actively check the printer every 5 minutes
retry_interval 1 ; Schedule host check retries at 1 minute intervals
max_check_attempts 3 ; Check each printer 10 times (max)
check_command check-host-alive ; Default command to check if printers are "alive"
notification_period workhours ; Printers are only used during the workday
notification_interval 60 ; Resend notifications every 30 minutes
notification_options d,r ; Only send notifications for specific host states
contact_groups admins ; Notifications get sent to the admins by default
statusmap_image printer.png
register 0 ; DONT REGISTER THIS - ITS JUST A TEMPLATE
}


# Define a template for switches that we can reuse
define host{
name generic-switch ; The name of this host template
use generic-host ; Inherit default values from the generic-host template
check_period 24x7 ; By default, switches are monitored round the clock
check_interval 5 ; Switches are checked every 5 minutes
retry_interval 1 ; Schedule host check retries at 1 minute intervals
max_check_attempts 3 ; Check each switch 10 times (max)
check_command check-host-alive ; Default command to check if routers are "alive"
notification_period 24x7 ; Send notifications at any time
notification_interval 60 ; Resend notifications every 30 minutes
notification_options d,r ; Only send notifications for specific host states
contact_groups admins ; Notifications get sent to the admins by default
statusmap_image switch.png
register 0 ; DONT REGISTER THIS - ITS JUST A TEMPLATE
}

# Define a template for routers that we can reuse
define host{
name generic-router ; The name of this host template
use generic-switch ; Inherit default values from the generic-host template
statusmap_image router.png
register 0 ; DONT REGISTER THIS - ITS JUST A TEMPLATE
}




###############################################################################
###############################################################################
#
# SERVICE TEMPLATES
#
###############################################################################
###############################################################################

# Generic service definition template - This is NOT a real service, just a template!

define service{
name generic-service ; The 'name' of this service template
active_checks_enabled 1 ; Active service checks are enabled
passive_checks_enabled 1 ; Passive service checks are enabled/accepted
parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems)
obsess_over_service 1 ; We should obsess over this service (if necessary)
check_freshness 0 ; Default is to NOT check service 'freshness'
notifications_enabled 1 ; Service notifications are enabled
event_handler_enabled 1 ; Service event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
is_volatile 0 ; The service is not volatile
check_period 24x7 ; The service can be checked at any time of the day
max_check_attempts 3 ; Re-check the service up to 3 times in order to determine its final (hard) state
normal_check_interval 5 ; Check the service every 10 minutes under normal conditions
retry_check_interval 1 ; Re-check the service every two minutes until a hard state can be determined
contact_groups admins ; Notifications get sent out to everyone in the 'admins' group
notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events
notification_interval 60 ; Re-notify about service problems every hour
notification_period 24x7 ; Notifications can be sent out at any time
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}


# Local service definition template - This is NOT a real service, just a template!

define service{
name local-service ; The name of this service template
use generic-service ; Inherit default values from the generic-service definition
max_check_attempts 3 ; Re-check the service up to 4 times in order to determine its final (hard) state
normal_check_interval 5 ; Check the service every 5 minutes under normal conditions
retry_check_interval 1 ; Re-check the service every minute until a hard state can be determined
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}
DBish
Posts: 5
Joined: Thu Oct 25, 2018 11:00 am

Re: Error: Template 'linux-server' specified in host definit

Post by DBish »

Ok, the long and the short of this seems to be that a bug or inconsistency may have been introduced on an update. So I've pretty much ended up rebuilding.

I've fully removed nagios3 (anyone else trying this may need to use nagios rather than nagios3 - all depends on your install I guess)

I backed up my .cfg files first - just in case, then

sudo apt-get remove nagios3
sudo apt-get remove --purge nagios3 (get rid of anything that the command above missed)
sudo apt autoremove (to clear out any unused dependencies)

I then installed Nagios Core 4 and this seems to be working correctly - probably because the config files are located in different directories to my previous install and this was then essentially a clean install of nagios - I used the link below to get this up and running.
https://support.nagios.com/kb/article/n ... tml#Ubuntu

Thanks for the help
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Error: Template 'linux-server' specified in host definit

Post by benjaminsmith »

Hi @DBish
I then installed Nagios Core 4 and this seems to be working correctly
Thanks for using Nagios, and I'm glad to hear you got it worked out. I will go ahead lock this forum topic.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked