Event Command to invoke PHP script

This forum was archived to /woltlab and is now in read-only mode.
  • Hi there,


    I'm trying to have Icinga2 (v2.3.4) create a ticket in the iTop ITSM tool automatically when services go into a hard down state.


    ITOP provides a script for Nagios ( https://wiki.openitop.org/doku…egrating_itop_with_nagios ) which I'm trying to adapt. I have tested running the script on command line and know that it works properly with my iTop installation.


    In the manual they discuss using an event_handler command, like so:


    define command{
    command_name create-iTop-ticket
    command_line <php path> <yourDirectory>/createTicket-nagios.php \"$HOSTNAME$\" \"$SERVICEDESC$\" \"$SERVICESTATE$\" \"$SERVICESTATETYPE$\" \"$LONGSERVICEOUTPUT$\"
    }


    And then setting it as an event_handler on a host or service like so:event_handler create-iTop-ticketevent_handler_enabled 1


    I tried adapting this to an EventCommand based on the documentation here ( http://docs.icinga.org/icinga2…ing-basics#event-commands ) like so:


    object EventCommand "itop-create-ticket" {
    import "plugin-event-command"


    command = [ PluginDir + "/icinga2/scripts/createTicket-nagios.php" ]


    arguments = {
    SERVICEDESC = "$service.name$"
    HOSTNAME = "$host.display_name$"
    SERVICESTATE = "$service.state$"
    SERVICESTATETYPE = "$service.state_type$"
    LONGSERVICEOUTPUT = "$service.output$"
    }
    }


    And then setting this on a service:


    event_command = "create-ticket"


    I'm fairly certain I'm misinterpreting the documentation in regards to EventCommands. First of all, I'm not sure if I'm setting arguments correctly like this, the script just takes 5 arguments it gets fed - I'm not sure if that's what's being done this way?


    EDIT: To Clarify how the script takes the arguments, it's like (command line)


    php createTicket-nagios.php <hostname> <servicename> <state> <statetype> <output>


    I'm fairly certain my problem is I don't understand how to feed these arguments correctly.



    If I missed providing any details, I'm sorry - let me know!


    Regards,


    Archy

    The post was edited 2 times, last by Archy ().

  • Similar to how CheckCommand arguments work. In your case it is probably easier to just add those as array elements anyways.


    Code
    1. command = [ SysconfDir + "/icinga2/scripts/createTicket-nagios.php", "$host.name$", "$service.name$", ... ]
  • Hi,


    Thank you for your time!


    I've changed the command like so, as you suggested:


    Code
    1. object EventCommand "itop-create-ticket" {
    2. import "plugin-event-command"
    3. command = [ SysconfDir + "/icinga2/scripts/createTicket-nagios.php", "$service.name$", "$host.display_name$", "$service.state$", "$service.state_type$", "$service.output$" ]
    4. }



    I've also edited the php file with:



    Code
    1. file_put_contents('debug.txt', print_r($argv,1));


    So I can see what happens when Icinga calls it.


    Furthermore, I've enabled the Icinga2 debuglog and see this:


    [2016-08-02 14:05:51 +0200] notice/Checkable: Executing event handler 'itop-create-ticket' for service '<HOSTNAME>!ssh'


    However it doesn't seem to touch the file (there is no debug.txt created).


    I thought it could be a permissions issue, so I've increased permissions (777) just to be sure that's not bothering it in any way.


    Any tips on where to look would be greatly appreciated!