Derrick Smith Header Image

Update for Nagios Eventhandler and GLPI 9.1+ Ticketing Integration

This post is an update to an earlier post regarding integrating Nagios with GLPI that can be found here.  Due to recent improvements in the GLPI distribution I decided to rewrite the eventhandlers.  You can find a link to GitHub at the bottom of this post.

One of the key pillars of information security is availability of resources and as a proponent of using open source solutions whenever possible I have chosen to utilize Nagios for monitoring and GLPI for helpdesk solutions.  Nagios provides powerful monitoring capabilities for equipment, hosts and services but doesn’t integrate with ticketing systems directly which can make tracking and reporting difficult.  GLPI is an ITIL based helpdesk solution that provides asset and incident/request management.  It offers generous reporting out of the box and a webservices API that can be used to extend the system.  When used together these two systems can provide a way to track host and service availability and a way to report on the health and resolution metrics of those systems over time.

As shown in my previous post regarding the integration of Nagios and GLPI, the marriage of the two systems is done using the built-in Nagios eventhandler action and the GLPI webservices API.  In previous versions of GLPI, a webservices plugin was used to create the API endpoints.  As of GLPI version 9.1, a webservices API is included in the core package.  The following procedure for integrating GLPI with Nagios will only work with GLPI 9.1+.  The event handlers have also been improved and use an object oriented approach.  The PHP xml_rpc extension has been replaced with the curl extension.  Be sure curl is installed before using these scripts.

GLPI Configuration

First, enable the API and create an API client on the API Settings page in GLPI located under Setup > General > API.   Enable both Authentication settings to allow your API client to login with credentials and an authentication key.  Be sure to copy the API URL and the API key for the client.  Although the event handler scripts can use any GLPI account that has ticket creation permission to create new tickets, it is recommended to create a new user account that will be used specifically for API transactions.

Nagios Configuration

Depending on the version of Nagios and the base operating system, Nagios could be installed into several possible locations.  I typically use Ubuntu Server and the directories listed below are for Nagios3 – your directories may be different.

First, open the host and service event handlers and change the variables at the top of each script to reflect your environment.  The scripts include the following variables:

## Required ##
$glpi_user				= '';
$glpi_password				= '';
$glpi_apikey				= '';
$glpi_host				= '';
$nagios_host				= '';
$verifypeer				= FALSE; // SETS curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
$logging				= TRUE;
$critical_priority			= 5;
$warning_priority			= 3;

## Optional ##
$glpi_requester_user_id		= '';
$glpi_requester_group_id	= '';
$glpi_watcher_user_id		= '';
$glpi_watcher_group_id		= '';
$glpi_assign_user_id		= '';
$glpi_assign_group_id		= '';

The initial variables are self-explanatory.  The ssloff variable should be set to true if your site is http, you are using a self-signed certificate for https or your ssl configuration prevents successful certificate validation.  The optional variables are used to control how new tickets are opened and if initial watchers and ticket owners are used.  Use these variables to control which groups or users are notified of new tickets and when tickets are closed.

After you have modified the scripts, copy them and the glpi_api class to the Nagios eventhandler directory.  Next, modify the Nagios commands.cfg file to include the following commands.  Be sure to replace the directory with the correct event handler directory for your Nagios installation.

# 'manage-host-tickets' command definition
define command{
command_name manage-host-tickets
command_line php /usr/share/nagios3/plugins/eventhandlers/manage-host-tickets.php hoststate="$HOSTSTATE$" hoststatetype="$HOSTSTATETYPE$" eventhost="$HOSTNAME$" hostattempts="$HOSTATTEMPT$" maxhostattempts="$MAXHOSTATTEMPTS$" hostproblemid="$HOSTPROBLEMID$" lasthostproblemid="$LASTHOSTPROBLEMID$"
}

# 'manage-service-tickets' command definition
define command{
command_name manage-service-tickets
command_line php /usr/share/nagios3/plugins/eventhandlers/manage-service-tickets.php servicehost="$HOSTNAME$" servicestate="$SERVICESTATE$" servicestatetype="$SERVICESTATETYPE$" hoststate="$HOSTSTATE$" eventhost="$HOSTNAME$" service="$SERVICEDISPLAYNAME$" serviceattempts="$SERVICEATTEMPT$" maxserviceattempts="$MAXSERVICEATTEMPTS$" lastservicestate="$LASTSERVICESTATE$" servicecheckcommand="$SERVICECHECKCOMMAND$" serviceoutput="$SERVICEOUTPUT$" longserviceoutput="$LONGSERVICEOUTPUT$"
}

Next, modify your host and service templates to include the above event handler commands,

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
		check_command                   check-host-alive
		event_handler		            manage-host-tickets
		max_check_attempts      1
		notification_interval   0
		notification_period     24x7
		notification_options    d,u,r
		contact_groups          admins
        register                        0       	; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, 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
		notification_interval           0		; Only send notifications on status change by default.
		event_handler		            manage-service-tickets
		is_volatile                     0
		check_period                    24x7
		normal_check_interval           5
		retry_check_interval            1
		max_check_attempts              4
		notification_period             24x7
		notification_options            w,u,c,r
		contact_groups                  admins
        register                        0       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
        }

After you are finished be sure to restart the Nagios service.  You will now receive helpdesk tickets in GLPI when alerts are created in Nagios and those tickets will be removed when the service or host has been restored.  GLPI will handle the appropriate  notifications.

Download Here

23 Comments

  1. Shaguu

    Hello Derrick,
    Unfortunately, the plugin seems to no longer work correctly with GLPI 9.5.x.
    Do you have any information on this?

  2. Hi Derrick.
    How can I set the entity on this code? I mean, we work with more than one group…
    Thanks in advance

  3. laurent TISON

    Hi Derrick,
    i’m getting stuk in following your tutorial

    Error :
    PHP Notice: Trying to get property of non-object in /usr/local/nagios/libexec/GLPI/glpi_api.php on line 30
    Failed: No Session Key

    Can you explain in more detail how to correctly fill your scripts in order to be able to generate a session with the GLPI API.

    This is how I informed it :
    ## Required ##
    $glpi_user = ‘nagios’;
    $glpi_password = ‘nagios’;
    $glpi_apikey = ‘Js1erlpevZmFqnTkkB0nbqwI945cf2N1idnyUUrI’;
    $glpi_host = ‘glpi.prive.domain.fu’;
    $nagios_host = ‘nagios.prive.domain.fu’;
    $verifypeer = FALSE; // SETS curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    $logging = TRUE;
    $critical_priority = 5;
    $warning_priority = 3;

    Thanks in advance for your time

    1. Derrick

      What does syslog show?

      Also, the GLPI host is the API url.

  4. […] be used to augment the software with additional features. Having worked with GLPI previously on my Nagios Event Handlers project, I was ready to dig in and create the functionality. Using the […]

  5. Teresa

    Hi! Thanks for your instructions but I can’t create the service! I was follow the intructions but I can’t see the error or omition.
    The manage-host-ticket works OK but manage-service-ticket NOT WORKING!!!
    Thanks!

  6. Sag

    Hi Derrick,
    I’m testing your plugin with Naemon’s monitoring solution. So far I have only used host notifications. The ticket is correctly created in GLPI, but when the host is up again, the closing of the ticket is not realized, despite the information in the logging. I am using version 9.2.4 of GLPI.

    Do you have an idea of ​​the problem ?

    Thank you

    Sag

  7. Sona Das

    Hi Derrick,
    Can you please tell me how can i integrate your solution with Nagios XI, as we are using Nagios XI in our environment.

  8. Daltox

    Hi, Derrick.

    I noticed that the code is not generating the “session_token” (Line 31 of glpi_api.php).
    Even by setting the login / password and Token parameters.

    By debugging each variable, I found the returning HTTP 404 code.

    You could explain better how to fill in the access data, or show how to fix the code.

    Ps .: Apache, PHP, MySQL and Nagios working perfectly.

  9. mattias

    Good day,
    do you have any idea why it creats a warning when the service OK and dont create ticket when the service realy is warning.
    its the oposite way of how it should work

    C:\ Drive Space on SERVER is in a Warning State. Please check that the service or check is running and responding correctly

    Check service status at montior.com

    Service Check Details
    Host = SERVER
    Service Check = C:\ Drive Space
    State = OK
    Check Attempts = 3/3
    Check Command = check_nt_disk_c!USEDDISKSPACE! -w 90 -c 95
    Check Output = 0

    1. mattias

      some compliments from logfile
      Dec 8 11:57:06 Naemon php: Manage Service Tickets: EventHost = HOST13-Idrac
      Dec 8 11:57:06 Naemon php: Manage Service Tickets: ServiceState = OK
      Dec 8 11:57:06 Naemon php: Manage Service Tickets: ServiceStateType =
      Dec 8 11:57:06 Naemon php: Manage Service Tickets: HostState = UP
      Dec 8 11:57:06 Naemon php: Manage Service Tickets: Service = FAN8
      Dec 8 11:57:06 Naemon php: Manage Service Tickets: ServiceAttempts = 3
      Dec 8 11:57:06 Naemon php: Manage Service Tickets: MaxServiceAttempts = 3
      Dec 8 11:57:06 Naemon php: Manage Service Tickets: LastServiceState = WARNING
      Dec 8 11:57:06 Naemon php: Manage Service Tickets: ServiceCheckCommand = check_idrac_fan8! HOSTADDRESS
      Dec 8 11:57:06 Naemon php: Manage Service Tickets: ServiceOutput = OK – System Board Fan1B: 5760 RPM – ENABLED/OK
      Dec 8 11:57:06 Naemon php: Manage Service Tickets: LongServiceOutput =
      Dec 8 11:57:06 Naemon php: Manage Service Tickets: Host is up, checking service state
      Dec 8 11:57:06 Naemon php: Manage Service Tickets: Service State is OK, checking Last Service State
      Dec 8 11:57:06 Naemon php: Manage Service Tickets: Last Service State Warning, checking for open Warning Tickets
      Dec 8 11:57:06 Naemon php: Manage Service Tickets: No Warning Tickets found, Creating new warning ticket

      btw running naemon. so not nagios but i dont think that should be so different

      1. Derrick

        Hello Mattias,

        I have updated the code. Please try and let me know.

        1. mattias

          some how the comment ended up abit down.
          tried to move it but it did not work

          //Mattias

          1. mattias

            Hi again Derrick
            now whit the new service check command it looks better.
            but nothing happens after these lines
            Host is up, checking service state
            Service State is WARNING, checking Service State Type
            Service State Type is HARD, checking service attempts
            Service Attempts = 3, checking Last Service State

            i looks like all is going ok now. but no ticket created. when looking in GLPI logs i can see that it searches for tickets but not createing

            //Mattias

  10. Ricardo

    Hi. Thanks for sharing.
    Works on Host but not in Services.
    Can Help?
    Thanks

    1. Derrick

      Hi Ricardo,

      I’ve updated these files to fix your issue and included logging and priority. They’re moved to GitHub, download link at the end of the article.

      1. mattias

        Hi Derrick, thanks for switft reply.

        it seems a little bit better now. it dont create ticket for OK status.
        but it dont create ticket for failure either. here comes some output
        Dec 11 09:21:08 Naemon php: Manage Service Tickets: Called Script
        Dec 11 09:21:08 Naemon php: Manage Service Tickets: EventHost = Server
        Dec 11 09:21:08 Naemon php: Manage Service Tickets: ServiceState = WARNING
        Dec 11 09:21:08 Naemon php: Manage Service Tickets: ServiceStateType =
        Dec 11 09:21:08 Naemon php: Manage Service Tickets: HostState = UP
        Dec 11 09:21:08 Naemon php: Manage Service Tickets: Service = C:\ Drive Space
        Dec 11 09:21:08 Naemon php: Manage Service Tickets: ServiceAttempts = 3
        Dec 11 09:21:08 Naemon php: Manage Service Tickets: MaxServiceAttempts = 3
        Dec 11 09:21:08 Naemon php: Manage Service Tickets: LastServiceState = WARNING
        Dec 11 09:21:08 Naemon php: Manage Service Tickets: ServiceCheckCommand = check_nt_disk_c!USEDDISKSPACE! -w 90 -c 95
        Dec 11 09:21:08 Naemon php: Manage Service Tickets: ServiceOutput = c:\ – total: 99.90 Gb – used: 91.46 Gb (92%) – free 8.44 Gb (8%)
        Dec 11 09:21:08 Naemon php: Manage Service Tickets: LongServiceOutput =
        Dec 11 09:21:08 Naemon php: Manage Service Tickets: Host is up, checking service state
        Dec 11 09:21:08 Naemon php: Manage Service Tickets: Service State is WARNING, checking Service State Type
        then it just is finnished

        //Mattias

        1. Derrick

          Dec 11 09:21:08 Naemon php: Manage Service Tickets: Called Script
          Dec 11 09:21:08 Naemon php: Manage Service Tickets: EventHost = Server
          Dec 11 09:21:08 Naemon php: Manage Service Tickets: ServiceState = WARNING
          Dec 11 09:21:08 Naemon php: Manage Service Tickets: ServiceStateType =
          Dec 11 09:21:08 Naemon php: Manage Service Tickets: HostState = UP
          Dec 11 09:21:08 Naemon php: Manage Service Tickets: Service = C:\ Drive Space
          Dec 11 09:21:08 Naemon php: Manage Service Tickets: ServiceAttempts = 3
          Dec 11 09:21:08 Naemon php: Manage Service Tickets: MaxServiceAttempts = 3
          Dec 11 09:21:08 Naemon php: Manage Service Tickets: LastServiceState = WARNING
          Dec 11 09:21:08 Naemon php: Manage Service Tickets: ServiceCheckCommand = check_nt_disk_c!USEDDISKSPACE! -w 90 -c 95
          Dec 11 09:21:08 Naemon php: Manage Service Tickets: ServiceOutput = c:\ – total: 99.90 Gb – used: 91.46 Gb (92%) – free 8.44 Gb (8%)
          Dec 11 09:21:08 Naemon php: Manage Service Tickets: LongServiceOutput =
          Dec 11 09:21:08 Naemon php: Manage Service Tickets: Host is up, checking service state
          Dec 11 09:21:08 Naemon php: Manage Service Tickets: Service State is WARNING, checking Service State Type

          I believe the issue is at this log entry “Dec 11 09:21:08 Naemon php: Manage Service Tickets: ServiceStateType =”. You do not seem to be supplying the servicestatetype. What does your eventhandler command look like? It should look like this:

          manage-service-tickets.php servicehost=”$HOSTNAME$” servicestate=”$SERVICESTATE$” servicestatetype=”$SERVICESTATETYPE$” hoststate=”$HOSTSTATE$” eventhost=”$HOSTNAME$” service=”$SERVICEDISPLAYNAME$” serviceattempts=”$SERVICEATTEMPT$” maxserviceattempts=”$MAXSERVICEATTEMPTS$” lastservicestate=”$LASTSERVICESTATE$” servicecheckcommand=”$SERVICECHECKCOMMAND$” serviceoutput=”$SERVICEOUTPUT$” longserviceoutput=”$LONGSERVICEOUTPUT$”

          I have updated the commands in the post to reflect the changes I previously made to the eventhandlers. Should resolve your issue.

      2. Ricardo

        Hi Derrick.
        I just tested and now it does not work. So far it did not work in services only. Now does not work on services or hosts.
        Can help me?
        Thanks

  11. Pyuesh Daya

    Hi Derrick

    Please ignore the above message, looks like it is working, even though the error above comes when testing from the command prompt.

    Please can you contact me, i have a few recommendations and would like assist by adding a category to the event handler.

    Thanks

    1. Derrick

      Hello Pyuesh,

      Please add your suggestions on GitHub. The link is at the end of the post. Thanks

  12. Pyuesh Daya

    Hi Derrick

    I’ve just upgraded my GLPI and am trying to get your new eventhandlers to work, but getting an error as below when running from the command line :

    PHP Warning: Missing argument 2 for GLPI_API::__construct(), called in /usr/local/libexec/nagios/eventhandlers/manage-host-tickets.php on line 31 and defined in /usr/local/libexec/nagios/eventhandlers/glpi_api.php on line 18
    PHP Warning: Missing argument 3 for GLPI_API::__construct(), called in /usr/local/libexec/nagios/eventhandlers/manage-host-tickets.php on line 31 and defined in /usr/local/libexec/nagios/eventhandlers/glpi_api.php on line 18
    PHP Warning: Missing argument 4 for GLPI_API::__construct(), called in /usr/local/libexec/nagios/eventhandlers/manage-host-tickets.php on line 31 and defined in /usr/local/libexec/nagios/eventhandlers/glpi_api.php on line 18
    PHP Warning: Missing argument 5 for GLPI_API::__construct(), called in /usr/local/libexec/nagios/eventhandlers/manage-host-tickets.php on line 31 and defined in /usr/local/libexec/nagios/eventhandlers/glpi_api.php on line 18

    Are you able to assist?

Leave a Reply

Your email address will not be published. Required fields are marked *