How do I add event handlers in the nagrestconf gui

25 views
Skip to first unread message

Cullen Philippson

unread,
Jun 6, 2018, 6:55:38 PM6/6/18
to nagrestconf-users
Hello,

I see some references to using a rest API to add an event handler, but is there a way to do it via the webGUI?  I'd like to include them in a Service Set.

Nagios docs:

NagRestConf doc:

Thank you,

Cullen

Cullen Philippson

unread,
Jun 7, 2018, 2:51:22 PM6/7/18
to nagrestconf-users
I found the line where is says "X" not available in the web front end.  I'll investigate further on how to use the csv2nag app.  Any examples would be more than welcome.

Thanks,

Cullen

Mark Clarkson

unread,
Jun 9, 2018, 8:14:14 PM6/9/18
to nagrestconf-users
Hi Cullen,
Sorry for the delay in getting back to you - not got much time to spare recently.

You can add the evenhandler using curl or nrcq, see https://github.com/mclarkson/nrcq.

First you need to fix a bug I found trying to make an example! nagctl needs updating, so on the nagios/nagrestconf host:

cd /usr/bin/
mv nagctl nagctl.old
chmod 0755 nagctl

Now for the example. I just installed nagrestconf and nagios using the nagrestconf docker installation instructions on my PC, then:
Using nrcq, you can view a serviceset called local-checks, with the service description, Num Users

$ nrcq http://localhost:8880/rest show/servicesets -f 'name:local-checks,svcdesc:Num Users'                                                                        

    name:local-checks
    template:svctmpl-lin
    command:check_users!-w 15 -c 20
    svcdesc:Num Users
    activechecks:1

Then add the event handler and view again:

$ nrcq http://localhost:8880/rest  modify/servicesets -d "name:local-checks" -d "svcdesc:Num Users" -d "eventhandler:myeventhandler"
SUCCESS
$ nrcq http://localhost:8880/rest show/servicesets -f 'name:local-checks,svcdesc:Num Users'

    name:local-checks
    template:svctmpl-lin
    command:check_users!-w 15 -c 20
    svcdesc:Num Users
    activechecks:1
    disable:0
    eventhandler:myeventhandler

Go back to the GUI and press Apply.
When you 'Re-apply service sets' to a host, or create a new host, and the event handler does not exist then the apply will fail with a descriptive 'nagios -v' error.

To delete the event handler use a '-', for example:

$ nrcq http://localhost:8880/rest  modify/servicesets -d "name:local-checks" -d "svcdesc:Num Users" -d "eventhandler:-"
SUCCESS
$ nrcq http://localhost:8880/rest show/servicesets -f 'name:local-checks,svcdesc:Num Users'

    name:local-checks
    template:svctmpl-lin
    command:check_users!-w 15 -c 25
    svcdesc:Num Users
    activechecks:1
    disable:0

Hope this helps!
Mark

Cullen Philippson

unread,
Jun 11, 2018, 6:18:59 PM6/11/18
to nagrestconf-users
Hi Mark,

Thank you.  I updated nagctl and got my powershell script to work remotely, but am getting an error 405 when trying to add the event handler.

[root@nagios src]# ./nrcq http://localhost/rest show/servicesets -f 'name:FooMaker-Prod,svcdesc:FooMaker web GUI 1502-IM_restart'

    name:FooMaker-Prod
    template:aba-svctmpl-foomaker
    command:check_http_foomaker!1508!60!60
    svcdesc:FooMaker web GUI 1508-IM_restart
    activechecks:1
    disable:0
    maxcheckattempts:3

[root@nagios src]# ./nrcq http://localhost/rest modify/servicesets -d "name:FooMaker-Prod" -d "svcdesc:FooMaker web GUI 1508-IM_restart" -d "eventhandler:check_nt_foomaker_restart"
ERROR: Status (405): ERROR 1029: Invalid command for this request type.

[root@nagios src]# ./nrcq http://localhost/rest show/servicesets -f 'name:FooMaker-Prod,svcdesc:FooMaker web GUI 1508-IM_restart'

    name:FooMaker-Prod
    template:aba-svctmpl-foomaker
    command:check_http_ifoomaker!1702!60!60
    svcdesc:FooMaker web GUI 1702-IM_restart
    activechecks:1
    disable:0
    maxcheckattempts:3

Mark Clarkson

unread,
Jun 12, 2018, 5:16:11 PM6/12/18
to nagrestconf-users
That error means that a GET request was sent instead of a POST. For modify/* it should be POST.
Maybe that error output was from the powershell script and it's using GET to modify?

Mark Clarkson

unread,
Jun 16, 2018, 5:32:50 PM6/16/18
to nagrestconf-users
Just in case someone else gets this error, it was caused by a proxy in between the nrcq and nagrestconf REST api rewriting the POST to a GET.
Reply all
Reply to author
Forward
0 new messages