Contact Creation API

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
J.A.K
Posts: 103
Joined: Wed Aug 05, 2020 11:39 am

Contact Creation API

Post by J.A.K »

So if you GET a contact you can see the contact template it has applied under use:

Code: Select all

[
    {
        "contact_name": "nagiosadmin",
        "alias": "Nagios Administrator",
        "host_notifications_enabled": "1",
        "service_notifications_enabled": "1",
        "host_notification_period": "nagiosadmin_notification_times",
        "service_notification_period": "nagiosadmin_notification_times",
        "host_notification_options": "d,u,r,f,s",
        "service_notification_options": "w,u,c,r,f,s",
        "host_notification_commands": [
            "xi_host_notification_handler"
        ],
        "service_notification_commands": [
            "xi_service_notification_handler"
        ],
        "email": "root@localhost",
       "use": [
            "xi_contact_generic"
        ]
    }
]
But using that in the POST to create a Contact with use=xi_contact_generic doesn't appear to work as far as I can tell like it does for hosts and services. I just wanted to confirm this should work right?
gsmith
Posts: 1253
Joined: Tue Mar 02, 2021 11:15 am

Re: Contact Creation API

Post by gsmith »

Hi,

You are correct that it should work. We were able to reproduce the issue
and have created a bug report. Thanks for reporting this to us.

Thanks
afrankmon
Posts: 1
Joined: Tue Oct 27, 2020 12:36 pm

Re: Contact Creation API

Post by afrankmon »

Is there an update available on adding a contact template through API. I am interested in automating contact creation and am experiencing the same issue. I can see the template when using GET. But when attempting to use POST or PUT the contact is not being updated with the specified template.

Thanks!
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Contact Creation API

Post by ssax »

While adding a contact template through the API hasn't been added yet, to get the contact template functionality to work when adding/updating a contact you can edit this file:

Code: Select all

/usr/local/nagiosxi/html/api/includes/utils-config.inc.php
Change this line (around line 888):

Code: Select all

$others = array('alias', 'contactgroups', 'minimum_importance', 'email', 'pager', 'can_submit_commands', 'retain_status_information', 'retain_nonstatus_information');
To this:

Code: Select all

$others = array('alias', 'contactgroups', 'minimum_importance', 'email', 'pager', 'can_submit_commands', 'retain_status_information', 'retain_nonstatus_information', 'use');
Then change this one (around line 954):

Code: Select all

$options = array('host_notifications_enabled', 'service_notifications_enabled', 'host_notification_period', 'service_notification_period', 'host_notification_options', 'service_notification_options', 'host_notification_commands', 'service_notification_commands', 'alias', 'contactgroups', 'minimum_importance', 'email', 'pager', 'can_submit_commands', 'retain_status_information', 'retain_nonstatus_information');
To:

Code: Select all

$options = array('host_notifications_enabled', 'service_notifications_enabled', 'host_notification_period', 'service_notification_period', 'host_notification_options', 'service_notification_options', 'host_notification_commands', 'service_notification_commands', 'alias', 'contactgroups', 'minimum_importance', 'email', 'pager', 'can_submit_commands', 'retain_status_information', 'retain_nonstatus_information', 'use');
That should do it for the "use" option to set a contact template when adding/updating a contact.

Please note that if you upgrade XI before development implements the change the change will be overwritten and you'll need to re-implement it after upgrading.
Locked