Page 1 of 1

Contact Creation API

Posted: Thu Apr 15, 2021 1:16 pm
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?

Re: Contact Creation API

Posted: Fri Apr 16, 2021 10:29 am
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

Re: Contact Creation API

Posted: Wed May 26, 2021 10:16 am
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!

Re: Contact Creation API

Posted: Fri May 28, 2021 9:33 am
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.