How can I deploy to more than one Nagios Server?

Support requests, bug reports, questions etc.
Locked
jedblack

How can I deploy to more than one Nagios Server?

Post by jedblack » Wed Jul 22, 2009 00:06

Hello All,

I have one nagios monitor and 3 nagios collectors....

I would like to use the "deploy" feature of Nconf -- but I dont see how it can deploy to more than one Nagios collector.

define('ALLOW_DEPLOYMENT', 1);
define('CONF_DEPLOY_URL', "https://webserver.mydomain.com/incoming_config.php");
define('CONF_DEPLOY_USER', "deployUser");
define('CONF_DEPLOY_PWD', "deployPass");


It appears that the CONF_DEPLOY_URL would be hard-set to 1 Nagios collector?

Mitch-Man

Re: How can I deploy to more than one Nagios Server?

Post by Mitch-Man » Fri Jul 24, 2009 16:55

Hello jedblack,

did you find a solution regarding this issue? I am also looking for a way to deploy the config to more than one server.

My goal is to set up one Monitoring Server (IT-Company) and several Collector Servers (customers' site). Pushing _the complete config_ to every Collector Server would not be the best thing anyway, would it? But I doubt that NConf has a solution for such a set-up.

Regards from Germany,
Michael.

Mitch-Man

Re: How can I deploy to more than one Nagios Server?

Post by Mitch-Man » Fri Jul 24, 2009 17:41

...maybe NConf can! At least kind of.

I just read the documentation once again:
A host is always linked to a collector. When the config is generated, all hosts linked to the same collector will be written to a file, including all their services and additional dependencies. Hosts not assigned to the same collector will be written to a different config file. This way, each collector will recieve its own set of config files. It will only monitor hosts assigned to it, all other information is disregarded.
http://sourceforge.net/apps/mediawiki/n ... s_NConf.3F
...and...
For small Nagios installations, where Nagios and NConf run on the same machine, or where there is only one collector and one monitor server, we provide certain deployment helpers for you to unpack and move the generated files to the right location.

For larger installations (large-scale, distributed setups), you must decide how to deploy the correct files to your servers on your own. For most sysadmins this is not a problem (mostly done with scp).
http://sourceforge.net/apps/mediawiki/n ... Deployment
...and...
If Nagios is running on a different server than NConf, you can configure and activate the deployment by following this guide: [Here comes the part with the incoming_config.php thing...]
http://sourceforge.net/apps/mediawiki/n ... Deployment
Maybe we both misunderstood what the incoming_config.php-Script is meant to be used for. Correct me if I am wrong, but I don't think it is for spreading your configuration to all your collector servers at different site. It is (see above) for deploying your configuration if you have only one monitor and one collector server.

Deploying your configuration to multiple collector servers at (different sites) need to be done as a separate step, for example with scp (see first quote above).

I will work on that and let you know how I solved it.

Regards from Germany,
Michael

Guest

Re: How can I deploy to more than one Nagios Server?

Post by Guest » Sun Jul 26, 2009 23:10

Hi,

just got it running! :-)

In my environment I have NConf only installed on my Monitoring Server. Then I went into NConf and added one Monitoring and two Collector Servers. Next thing I did was adding a couple of Hosts and services to check and within the host configuration I pointed to the Collector Server that will be responsible for the active checks (NConf -> Hosts -> Modify -> "monitored by").

When you click on "Generate Nagios Config" and run the deploy_local.sh script on the Monitoring Server you find one folder for each Collector Server in the nagios/etc/-directory. You just have to copy the content of each folder to the corresponding Collector Server (and of course you have to tell nagios on that machine to read those config-files / -folders).

I copy the content of these folders via scp from the Monitoring Server. I made a script for every Collector Server (quick and dirty, I know...):

/usr/local/bin/scp_NagiosCollector1.sh

Code: Select all

scp -r /usr/local/nagios/etc/collectorCollector1/ /usr/local/nagios/etc/global/ www-data@NagiosCollector1.foo.bar:/usr/local/nagios/etc/
I hope that was a little help for you. If you need more information please feel free to post your questions!

Regards from Germany,

Michael.

User avatar
agargiulo
NConf developer
NConf developer
Posts: 725
Joined: Fri Mar 06, 2009 17:50
Location: Zurich, Switzerland
Contact:

Re: How can I deploy to more than one Nagios Server?

Post by agargiulo » Mon Jul 27, 2009 17:02

Hi guys.

You're right about the deployment feature: it is not intended for NConf to do the whole deployment logic of copying files to several servers. You can either use a script supplied in the ADD-ONS folder to unpack & copy the config locally, or you can use the http(s) upload feature to upload the generated archive to one (1) remote server. How you deploy the config from there is completely up to you.
For instance, in our environment we upload the generated config to a webserver which also is a Cfengine server and supplies configuration files for all systems in our environment.
A more sophisticated deployment process in NConf is something which is on the to-do list for future releases, but i have to admit that the priority is not very high for this, simply because there are so many different requirements out there and experienced server admins usually prefer to implement their own solutions.

Cheers,
Angelo

jedblack
beginner
beginner
Posts: 9
Joined: Mon Jul 27, 2009 20:29

Re: How can I deploy to more than one Nagios Server?

Post by jedblack » Mon Jul 27, 2009 20:33

I figured out how I can do this, you need to edit two files in the nconf root directory
1. ~/config/nconf.php
adjust as follows....

Code: Select all

# Config deployment
#
define('ALLOW_DEPLOYMENT', 1);
define('CONF_DEPLOY_URL',  "http://poller1.qprvt.com/incoming/incoming_config.php");
define('CONF_DEPLOY_URL1',  "http://poller1.prvt.com/incoming/incoming_config.php");
define('CONF_DEPLOY_URL2',  "http://poller1.wst1.com/incoming/incoming_config.php");
....add more CONF_DEPLOY_URL3,4,5 for however many pollers you need to push too.....
define('CONF_DEPLOY_USER', "nconf");
define('CONF_DEPLOY_PWD',  "nc0nf123");
2. ~/deploy.config.php
adjust as follows....

Code: Select all

<?php
    require_once 'config/main.php';
    require_once 'include/head.php';

    if(ALLOW_DEPLOYMENT == 1 && $_POST["status"] == "OK"){
        $post_data = array();

        $post_data['file'] = "@output/NagiosConfig.tgz";

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, CONF_DEPLOY_URL);
        curl_setopt($ch, CURLOPT_POST, 1 );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
	    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

        if((defined('CONF_DEPLOY_USER') and CONF_DEPLOY_USER != "") and (defined('CONF_DEPLOY_PWD') and CONF_DEPLOY_PWD != "")){
        	curl_setopt($ch, CURLOPT_USERPWD, CONF_DEPLOY_USER.":".CONF_DEPLOY_PWD);
        }

        $postResult = curl_exec($ch);

        curl_close($ch);

        if($postResult == "OK"){
            // Log to history
            history_add("general", "config", "deployed");

            echo "<br><b>Poller1.qprvt   Config deployment completed successfully.  Please allow 60secs for Nagios to pickup changes.</b>";
        }else{
            echo "<br><div id=attention>Poller1.qprvt   Config deployment failed!</div>";
        }
    }else{
        echo "<br><div id=attention>Deployment functionality is currently disabled.</div>";
    }

##################
## REPEATED BLOCK OF CODE FOR CONF_DEPLOY_URL1 (aka. poller1.prvt.com)
##################

    if(ALLOW_DEPLOYMENT == 1 && $_POST["status"] == "OK"){
        $post_data = array();

        $post_data['file'] = "@output/NagiosConfig.tgz";

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, CONF_DEPLOY_URL1);
        curl_setopt($ch, CURLOPT_POST, 1 );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

        if((defined('CONF_DEPLOY_USER') and CONF_DEPLOY_USER != "") and (defined('CONF_DEPLOY_PWD') and CONF_DEPLOY_PWD != "")){
                curl_setopt($ch, CURLOPT_USERPWD, CONF_DEPLOY_USER.":".CONF_DEPLOY_PWD);
        }

        $postResult = curl_exec($ch);

        curl_close($ch);

        if($postResult == "OK"){
            // Log to history
            history_add("general", "config", "deployed");

            echo "<br><b>Poller1.prvt   Config deployment completed successfully.  Please allow 60secs for Nagios to pickup changes.</b>";
        }else{
            echo "<br><div id=attention>Poller1.prvt   Config deployment failed!</div>";
        }
    }else{
        echo "<br><div id=attention>Deployment functionality is currently disabled.</div>";
    }
##################
## REPEATED BLOCK OF CODE FOR CONF_DEPLOY_URL2 (aka. poller1.wst1.com)
##################
    if(ALLOW_DEPLOYMENT == 1 && $_POST["status"] == "OK"){
        $post_data = array();

        $post_data['file'] = "@output/NagiosConfig.tgz";

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, CONF_DEPLOY_URL2);
        curl_setopt($ch, CURLOPT_POST, 1 );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

        if((defined('CONF_DEPLOY_USER') and CONF_DEPLOY_USER != "") and (defined('CONF_DEPLOY_PWD') and CONF_DEPLOY_PWD != "")){
                curl_setopt($ch, CURLOPT_USERPWD, CONF_DEPLOY_USER.":".CONF_DEPLOY_PWD);
        }

        $postResult = curl_exec($ch);

        curl_close($ch);

        if($postResult == "OK"){
            // Log to history
            history_add("general", "config", "deployed");

            echo "<br><b>Poller1.wst1   Config deployment completed successfully.  Please allow 60secs for Nagios to pickup changes.</b>";
        }else{
            echo "<br><div id=attention>Poller1.wst1  Config deployment failed!</div>";
        }
    }else{
        echo "<br><div id=attention>Deployment functionality is currently disabled.</div>";
    }

    require_once 'include/foot.php';
?>

I basicly repeated the deploy function for each remote poller I needed to push the config too. You need to repeat the block of code in "deploy_config.php" for each CONF_DEPLOY_URL you define in ~/config/nconf.php. Please sure to adjust the "Config deployment completed successfully" TEXT to reflect each poller you pushed too, otherwise you will just see the repeated messages "Config deployment completed successfully" for how ever many pollers you have when you click the "Deploy" button. The deploy still will work, but it nice to know which monitor/collector might have failed the get and update.
Last edited by jedblack on Mon Jul 27, 2009 20:43, edited 2 times in total.

jedblack
beginner
beginner
Posts: 9
Joined: Mon Jul 27, 2009 20:29

Re: How can I deploy to more than one Nagios Server?

Post by jedblack » Mon Jul 27, 2009 20:40

Mitch-Man wrote:Hello jedblack,

did you find a solution regarding this issue? I am also looking for a way to deploy the config to more than one server.

My goal is to set up one Monitoring Server (IT-Company) and several Collector Servers (customers' site). Pushing _the complete config_ to every Collector Server would not be the best thing anyway, would it? But I doubt that NConf has a solution for such a set-up.

Regards from Germany,
Michael.
Hi Mich-Man,

Please see my post to this thread it describes how I setup the push to multiple pollers. We are pushing all the config for every server to each pollers, In your case I dont really see an issue as long as you adjust the "nagios.cfg" on each poller to only look at the config directory of the respective poller.

Nconf deploy all the config for each monitor/collector in a directory which is the title of the monitor or poller itself. The only reason I can see that you would not want to push all the config to every monitor/collector is if there is sensitive network information and/or confidentiality agreements. We are one company with mutiple geographic location -- the method I use to push the config to each poller seem to work just fine.... I have 1 monitor and 3 collectors (soon to be 6 collectors)

User avatar
agargiulo
NConf developer
NConf developer
Posts: 725
Joined: Fri Mar 06, 2009 17:50
Location: Zurich, Switzerland
Contact:

Re: How can I deploy to more than one Nagios Server?

Post by agargiulo » Tue Jul 28, 2009 12:38

We will consider providing this functionality in the future. The CONF_DEPLOY_URL constant could easily be changed to an array, and the http(s) upload could be run in a loop. I will add this to the list of features for one of the next releases.

Thank you.

jedblack
beginner
beginner
Posts: 9
Joined: Mon Jul 27, 2009 20:29

Re: How can I deploy to more than one Nagios Server?

Post by jedblack » Tue Jul 28, 2009 16:55

Hi Agargiulo,

Let me start by saying thanks so much for your time/effort/ and surely money (in one way or another) to keep this project moving and up to date. It's a fantastic tool which has made my life much more enjoyable with Nagios.

Adding that array/loop would be fantastic! Look forward to seeing the next release!

Have a great day....

Jed-

melber
beginner
beginner
Posts: 11
Joined: Tue Jun 30, 2009 16:22

Re: How can I deploy to more than one Nagios Server?

Post by melber » Thu Jul 30, 2009 19:04

Hi,

actually it is prety easy to deploy the config out of nconf on several servers sorry that i can´t post the config file here it is at work and i am on holiday now.

here is te script we use at the moment on our test servers ( at the moment it is undergoing another rewrite to make it more flexible ) but it works pretty good in our environment. it needs md5deep from sourceforge rsync and ssh to work. at the moment i havn´t implemented a restart of nagios with backup and config check prior to restart. maybe you will need to rewrite some parts to your needs. the config is written as a shell script like this:

Code: Select all

rsyncproc=/bin/rsync
the serverconfig is the same but one line one server:

Code: Select all

hostaddr server serverdir sshalias
more options will follow with the rewrite.


and finaly here is the script but please test it before using it. it is still work in progress.

Code: Select all

#!/bin/bash
#
# Author: Melanie Bernkopf <Melanie.Bernkopf@jku.at>
#
# Syncronisation script for use in distributed nagios environments
# 

set -x

tmpdir=`mktemp -d -p temp/`
touch $tmpdir

test -x $rsyncproc
if [ $? != 0 ]
then
    echo "missing rsync program"
    exit 1
else
    tar -zxf output/NagiosConfig.tgz -C $tmpdir
    . config/sync.cfg
    cd $tmpdir
fi



function do_update {
while read hostaddr server serverdir sshalias 
do

$md5sumproc -c $nconfroot/config/md5-$serverdir
if [ $? = 1 ]
then
      echo "syncing slave config files"

	  if [ $syncproto == rsync ]
	  then
      		$rsyncproc --partial --recursive --password-file=/etc/rsync.secrets $serverdir rsync://$rsyncuser@$hostaddr/nagios
      elif [ $syncproto == ssh ]
      then
      		scp -r $serverdir $sshalias:/$nagiosdir/ 
      else
      		echo "Please configure syn method by setting syncproto in config"
      fi

      if [ $? = 0 ]
      then
	  echo "RSYNC: successfully done "
	  retval=0
      else
	  echo "RSYNC: didn't finish properly see rsync log for details "
	  retval=1
      fi

	  if [ $syncproto == rsync ]
	  then
      		$rsyncproc --partial --recursive --password-file=/etc/rsync.secrets global rsync://$rsyncuser@$hostaddr/nagios
      elif [ $syncproto == ssh ]
      then
      		scp -r $serverdir $sshalias:/$nagiosdir/
      else
      		echo "Please configure syn method by setting syncproto in config"
      fi

      if [ $? = 0 ]
      then
	  echo "RSYNC: successfully done "
	  retval=0
      else
	  echo "RSYNC: didn't finish properly see rsync log for details "
	  retval=1
      fi

      echo "fetching new md5sums"
      $md5deppproc -rl $serverdir > $nconfroot/config/md5-$serverdir
      echo -ne "$md5deppproc -rl $serverdir > $nconfroot/config/md5-$serverdir\n"
else
      :
fi

done < $nconfroot/config/servers.cfg
}

function do_update_all {
while read hostaddr server serverdir
do
      echo "syncing slave config files"

	  if [ $syncproto == rsync ]
	  then
      		$rsyncproc --partial --recursive --password-file=/etc/rsync.secrets $serverdir rsync://$rsyncuser@$hostaddr/nagios
      elif [ $syncproto == ssh ]
      then
      		scp -r $serverdir $sshalias:/$nagiosdir/
      else
      		echo "Please configure syn method by setting syncproto in config"
      fi

      if [ $? = 0 ]
      then
	  echo "RSYNC: successfully done "
	  retval=0
      else
	  echo "RSYNC: didn't finish properly see rsync log for details "
	  retval=1
      fi

	  if [ $syncproto == rsync ]
	  then
      		$rsyncproc --partial --recursive --password-file=/etc/rsync.secrets global rsync://$rsyncuser@$hostaddr/nagios
      elif [ $syncproto == ssh ]
      then
      		scp -r $serverdir $sshalias:/$nagiosdir/
      else
      		echo "Please configure syn method by setting syncproto in config"
      fi

      if [ $? = 0 ]
      then
	  echo "RSYNC: successfully done "
	  retval=0
      else
	  echo "RSYNC: didn't finish properly see rsync log for details "
	  retval=1
      fi

      echo "fetching new md5sums"
      $md5deppproc -rl $serverdir > $nconfroot/config/md5-$serverdir

done < config/servers.cfg
}

$md5sumproc -c $nconfroot/config/md5-global
if [ $? != 0 ]
then
	do_update_all
	$md5deppproc -rl global > $nconfroot/config/md5-$serverdir
else
	do_update
	$md5deppproc -rl global > $nconfroot/config/md5-$serverdir
fi

cd $nconfroot
rm -rf $tmpdir
for implementation in the webinterface i took the create config things and rewrote the ajax things to take the right scripts.

User avatar
agargiulo
NConf developer
NConf developer
Posts: 725
Joined: Fri Mar 06, 2009 17:50
Location: Zurich, Switzerland
Contact:

Re: How can I deploy to more than one Nagios Server?

Post by agargiulo » Fri Jul 31, 2009 11:36

Hi Melanie.

Nice script! If you like, we could discuss implementing it. It would be cool to have rsync/ssh deployment functionality built into NConf.
If you are interested, let me know once you've re-written the script and everything.

Have a nice holiday.
Cheers, Angelo

melber
beginner
beginner
Posts: 11
Joined: Tue Jun 30, 2009 16:22

Re: How can I deploy to more than one Nagios Server?

Post by melber » Tue Aug 11, 2009 13:09

Hi,

of course you can have those script and everything we changed to make it work.

here is the main conig file that is placed under configs/sync.cfg

Code: Select all

#!/bin/bash

nconfroot="/var/www/html/nconf"

md5deppproc="/usr/local/bin/md5deep"
md5sumproc="/usr/bin/md5sum"

syncproto=rsync

rsyncproc="/usr/bin/rsync"
rsyncuser="nconf"
and the file config/servers.cfg

Code: Select all

192.168.3.176 a-nagios a_collector master /etc/nagios/objects/
in include ajax we have a file named exec_upload_config.php containing the follwoing:

Code: Select all

<?php
    require_once 'config/main.php';
//    require_once 'include/head.php';
    $status = "OK";

    // check if "temp" dir is writable
    if(!is_writable(NCONFDIR."/temp/")){
        echo "<br><div id=attention>Could not write to 'temp' folder. Cannot generate config.</div>";
        $status = "error";
        exit;
    }


    // check if generate_config script is executable
    if(!is_executable(NCONFDIR."/bin/generate_config.pl")){
        echo "<br><div id=attention>Could not execute generate_config script. <br>The file '".NCONFDIR."/bin/generate_config.pl' is not executable.</div>";
        $status = "error";
        exit;
    }


    // check if existing "output/NagiosConfig.tgz" is writable
    if(file_exists(NCONFDIR."/output/NagiosConfig.tgz" and !is_writable(NCONFDIR."/output/NagiosConfig.tgz"))){
        echo "<br><div id=attention>Cannot rename ".NCONFDIR."/output/NagiosConfig.tgz. Access denied.</div>";
        $status = "error";
        exit;
    }

    // check if static config folder(s) are readable
    foreach ($STATIC_CONFIG as $static_folder){
        if(!is_readable($static_folder)){
            echo "<br><div id=attention>Could not access static config folder '".$static_folder."'.";
            echo "<br>Check your \$STATIC_CONFIG array in 'config/nconf.php'.</div>";
            $status = "error";
            exit;
        }
    }


    // Log to history
    history_add("general", "config", "uploaded");
?>

<table border=0>
    <tr><td>
        <b>Uploading config:</b><pre><?php system(NCONFDIR."/bin/nconf-sync.sh") ?></pre><br>


    </td></tr>
</table>



<script type="text/javascript">



</script>


you only need to define the link the same as the genrate config in the side menu and add the permissions to make it accessable. no big problem for a sysadmin to implement.

melber
beginner
beginner
Posts: 11
Joined: Tue Jun 30, 2009 16:22

Re: How can I deploy to more than one Nagios Server?

Post by melber » Tue Aug 18, 2009 15:23

Hi,

I have now a worked over version of our script. If you send me a mail how i can reach you i can send you a patchfile to patch the current stable release with my changes and do some tests. Please contact me for further information.

User avatar
agargiulo
NConf developer
NConf developer
Posts: 725
Joined: Fri Mar 06, 2009 17:50
Location: Zurich, Switzerland
Contact:

Re: How can I deploy to more than one Nagios Server?

Post by agargiulo » Mon Sep 07, 2009 17:22

Hi.

Sorry for the late reply. I was away.
You may contact me anytime under my users.sourceforge.net address...

user: agargiulo

Locked