Raw Import API via Powershell
Posted: Tue Jan 29, 2019 6:47 am
I am trying to do Raw Import to add a contact to nagios via the API in powershell, i seem to be missing a part of the command and cant figure out how to do it-
The curl command is
I've tested this and it does correctly add the contact
This is the same command in Powershell-
This reports success-
success
-------
Imported configuration data. Config imported but not yet applied.
but doesn't actually add the data.
The key bit I am missing is the 'define contact' line - but I'm not sure how to turn that into powershell syntax, anyone any idea?
The curl command is
Code: Select all
curl -XPOST "https://nagiosserver/nagiosxi/api/v1/config/import?apikey=bigkey&pretty=1" -d '
define contact {
contact_name test
host_notifications_enabled 0
service_notifications_enabled 0
host_notification_period none
service_notification_period none
host_notification_options n
service_notification_options n
host_notification_commands xi_host_notification_handler
service_notification_commands xi_service_notification_handler
}'
This is the same command in Powershell-
Code: Select all
$bodycontact = @{
contact_name="powershelltest"
host_notifications_enabled=0
service_notifications_enabled=0
host_notification_period="none"
service_notification_period="none"
host_notification_options="n"
service_notification_options="n"
host_notification_commands="xi_host_notification_handler"
service_notification_commands="xi_service_notification_handler"
}
Invoke-RestMethod -Method Post -Uri "http://nagiosserver/nagiosxi/api/v1/config/import?apikey=bigkey&define=contact" -Body $bodycontact
success
-------
Imported configuration data. Config imported but not yet applied.
but doesn't actually add the data.
The key bit I am missing is the 'define contact' line - but I'm not sure how to turn that into powershell syntax, anyone any idea?