Nagios

Configuration

Config files:

  • cgi.cfg - main CGI config file
  • nagios.cfg - main config file
  • resource.cfg - main resource file ( used for MACROs )
  • objects - folder with a various *.cfg files

What are objects?

Objects are all the elements that are involved in the monitoring and notification logic. Types of objects include:

  • Services
  • Service Groups
  • Hosts
  • Host Groups
  • Contacts
  • Contact Groups
  • Commands
  • Time Periods
  • Notification Escalations
  • Notification and Execution Dependencies

Where Are Objects Defined?

Objects can be defined in one or more configuration files and/or directories that you specify using the cfg_file and/or cfg_dir directives in the main configuration file.

Host and hostgroup

define a host:

define host{
        use    linux-server   ; Name of host template to use. 
                                       ; This host definition will inherit all variables that are defined
                                       ; in (or inherited by) the linux-server host template definition.
        host_name         node
        alias                   node
        address             10.0.88.20
        }

define a hostgroup:

define hostgroup{
        hostgroup_name  linux-servers2 ; The name of the hostgroup, must be unique
        alias           Linux Servers 2; Long name of the group
        members         node     ; Comma separated list of hosts that belong to this group
        }

define a ‘template for generic-host:

# 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
        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!
        }

and linux-server who is using generic-host 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              10              ; 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           120             ; 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!
        }

Service

define check_ping command in commands.cfg

# 'check_ping' command definition
define command{
        command_name    check_ping
        command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5
}

define service in localhost.cfg

define service{
        use    local-service ; Name of service template to use
        host_name    localhost
        service_description    PING
	check_command    check_ping!100.0,20%!500.0,60% ; cmd!warning!critical
}

Webinject

Complete howto - http://www.webinject.org/plugin.html

define main config file config.xml

<testcasefile></testcasefile>
<globalhttplog>onfail</globalhttplog>
<reporttype>nagios</reporttype>
<timeout>400</timeout>
<globaltimeout>400</globaltimeout>
<useragent>Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 (WebInject)</useragent>

define test.xml

<testcases repeat="1">

<testvar varname="ELB">SOME_URL/</testvar>
<testvar varname="STATUS">/app-feedback-server/status</testvar>


<case
    id="1"
    description1="PRODELB  - AFS"
    errormessage="PRODELB  - AFS  - Unable to obtain status"
    url="${ELB}${STATUS}"
    verifypositive='OK'
        verifynegative="PRODELB - AFS - error has occurred"
/>

</testcases>