Page 1 of 1

Automate BPI servicegroups and hostsgroups syncs

Posted: Wed Oct 07, 2015 9:23 pm
by tylerhoadley
I've been trying to automate the bpi hostsgroups and servicehosts syncs within the bpi module.

I believe this maybe possible via a webinject.pl script that I can run in Xi or via a /usr/bin/perl crontab entry. I'm not achieving the desired result although my script finishing without issue. So either I'm missing something during login or not passing proper args. Any help or knowledge as to what the index.php is expecting would be great

like I mentioned, this seems to complete all transaction correctly but it doesn't actually update the bpi group syncs. I used HTTP Live headers to capture the HTTP traffic commands, this is what I filtered out to try.

here is my attempt of using webinject..pl cases

Code: Select all

<testcases repeat="1">


<case
	id="1"
	method="get"
	url="http://server.example.com/nagiosxi/login.php?redirect=/nagiosxi/admin/index.php%3f&noauth=1"
        verifyresponsecode="200"
        sleep="1"
/>

<case
     	id="2"
	method="post"
        url="http://server.example.com/nagiosxi/login.php"
        postbody="nsp=cc483f1914b7e21c80f64054a69e4485&page=auth&debug=&pageopt=login&username=nagiosadmin&password=***********&loginButton=Login"
        posttype="application/x-www-form-urlencoded"
        verifypositive="Nagiosxi"
        sleep="1"
/>

<case
     	id="3"
	method="get"
        url="http://server.example.com/nagiosxi/index.php"
        verifyresponsecode="302"
        sleep="1"
/>



<case
     	id="4"
	method="get"
        url="http://server.example.com/nagiosxi/includes/components/nagiosbpi/index.php?cmd=syncservicegroups"
	verifyresponsecode="200"
        sleep="5"
/>

<case
     	id="5"
	method="get"in my last attempt, just in case 
        url="http://server.example.com/nagiosxi/includes/components/nagiosbpi/index.php?cmd=synchostgroups"
	verifyresponsecode="200"
        sleep="5"
/>


</testcases>

I added sleep to help troubleshoot

Any help would be great.

Re: Automate BPI servicegroups and hostsgroups syncs

Posted: Thu Oct 08, 2015 2:24 pm
by ssax
This may help you, I've taken it from a ticket I've worked on (the first part fixes a bug).

Edit this file:

Code: Select all

/usr/local/nagiosxi/html/includes/components/nagiosbpi/api_tool.php

Find this code (around line 119):

Code: Select all

function route_command($args)
{
    $cmd = grab_array_var($args, 'cmd', '');

Change it to:

Code: Select all

function route_command($args)
{
    bpi_init();
    $cmd = grab_array_var($args, 'cmd', '');

Now when you sync your hostgroups/servicegroups it will update rather than replace keeping your existing settings.

You can add them to a new file under /etc/cron.d so that cron will run them ever 5 minutes (or whatever setting you want):

Code: Select all

*/5 * * * * nagios /usr/bin/php -q /usr/local/nagiosxi/html/includes/components/nagiosbpi/api_tool.php --cmd=synchostgroups" > /usr/local/nagiosxi/var/bpi-hg.log 2>&1
*/5 * * * * nagios /usr/bin/php -q /usr/local/nagiosxi/html/includes/components/nagiosbpi/api_tool.php --cmd=syncservicegroups" > /usr/local/nagiosxi/var/bpi-sg.log 2>&1

Re: Automate BPI servicegroups and hostsgroups syncs

Posted: Mon Oct 19, 2015 1:43 pm
by tylerhoadley
Awesome, works great.

however you have a " in both cmd calls (--cmd=synchostgroups" --cmd=syncservicegroups") that isn't needed

Prior to adding the cron, I ran the below to test the desired bpi output

Code: Select all

# sudo -u nagios /usr/bin/php -q /usr/local/nagiosxi/html/includes/components/nagiosbpi/api_tool.php --cmd=synchostgroups
CMD: synchostgroups
MSG: Backup successfully created.BPI configuration applied successfully!

# sudo -u nagios /usr/bin/php -q /usr/local/nagiosxi/html/includes/components/nagiosbpi/api_tool.php --cmd=syncservicegroups
CMD: syncservicegroups
MSG: Backup successfully created.BPI configuration applied successfully!
Then I appended this to the /etc/cron.d/nagiosxi cron file (I'll maintain this change as I upgrade version and nagiosxi file gets updated)

Code: Select all

*/5 * * * * nagios /usr/bin/php -q /usr/local/nagiosxi/html/includes/components/nagiosbpi/api_tool.php --cmd=synchostgroups > /usr/local/nagiosxi/var/bpi-hg.log 2>&1
*/5 * * * * nagios /usr/bin/php -q /usr/local/nagiosxi/html/includes/components/nagiosbpi/api_tool.php --cmd=syncservicegroups > /usr/local/nagiosxi/var/bpi-sg.log 2>&1
Cheers,

Re: Automate BPI servicegroups and hostsgroups syncs

Posted: Mon Oct 19, 2015 4:58 pm
by ssax
Woops, nice catch! :oops: Thanks for posting the solution.