Giter Site home page Giter Site logo

vahidhedayati / nagios-failover Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 144 KB

script to failover nagios servers if and when their down - automtically done via bash script

Home Page: http://exchange.nagios.org/directory/Utilities/nagios-fail-over/details

Shell 100.00%

nagios-failover's Introduction

nagios-failover

script to failover nagios servers if and when their down - automtically done via bash fail over script that will require some ground work to be done in order to achieve the end result of each nagios server looking out for one another.

I have also done a few other things

cd /etc/;

ln -s /usr/local/nagios/etc ./nagios

cd /etc/nagios;

ln -s /usr/local/nagios/libexec ./plugins

Requirements.

  1. Actual nagios cfg files -

CMS (configuration Management System - puppet,chef or cfengine)

I have used puppet and used the recursive folder plugin to push all the actual cfg files to nagios nodes:

Unison configuration :

You could use the unison protocol and add /usr/local/nagios/etc/objects/$company as a folder to also be synchronised and bypass all this CMS requirements. You would need to move :

   commands.cfg
   admin.cfg
   timeperiods.cfg
   templates.cfg
   to :  /usr/local/nagios/etc/objects/$company  and update the reference in nagios.cfg accordingly

Within the script update and move the sync_path variable below $company variable: SYNC_PATH="/opt/nagios-sync /usr/local/nagios/etc/objects/$company"

CMS Way puppet config

    $objects="/usr/local/nagios/etc/objects"
    $company_objects="$objects/company"

    file { "$company_objects":
            ensure => directory, # so make this a directory
            recurse => true, # enable recursive directory management
            purge => true, # purge all unmanaged junk
            force => true, # also purge subdirs and links etc.
            owner => "nagios",
            group => "nagios",
            mode => 0644, # this mode will also apply to files from the source directory
            # puppet will automatically set +x for directories
            source => "puppet:///modules/nagios/company",
    }

Recursive company folder

so inside: files/company I have currently two data centres in each of these data centres:

files/company/datacentre1
   - files/company/datacentre1/prod
      -- files/company/datacentre1/prod/hosts
      -- files/company/datacentre1/prod/services

 pwd
 /usr/local/nagios/etc/objects
 
 tree
 .
 |-- admin.cfg
 |-- commands.cfg
 |-- generic-host.cfg
 |-- generic-service.cfg
 |-- company_folder
 |   |-- README
 |   |-- datacentre1
 |   |   |-- development
 |   |   |   |-- hosts
 |   |   |   |   `-- development-servers.cfg
 |   |   |   `-- services
 |   |   |       |-- development-sources.cfg
 |   |   |       `-- generic-development.cfg
 |   |   |-- uat
 |   |   |   |-- hosts
 |   |   |   |   `-- uat-servers.cfg
 |   |   |   `-- services
 |   |   |       |-- apache-uat.cfg

and so on.... I have defined the path to each datacentre in the nagios.cfg:

Nagios server 1

 # Datacentre1 servers - services
 cfg_dir=/etc/nagios/objects/company/datacentre1

Nagios server 2

 # Datacentre1 servers - services
 cfg_dir=/etc/nagios/objects/company/datacentre2

Nagios will then read all the files within the sub folders of each datacentre recursivly on each nagios host... (this simplify definition of each config file etc and makes it a lot easier to script this solution.

So once you have puppet pushing out the configuration which in short all nagios hosts have all the configrations but only load up the relevant datacentre folder for what it is supposed to monitor:

  1. unison protocol to synchronise amongst nagios hosts

yum install unison or apt-get install unison

  1. A shared folder amongst all nagios servers

In the script I have defined /opt/nagios-sync

mkdir /opt/nagios-sync
mkdir /opt/nagios-sync/config_backup
touch /opt/nagios-sync/status.log
chown -R nagios:nagois /opt/nagios-sync
  1. Nagios user with sudoers access to restart nagios and access files in /opt/nagois-sync sudo -i

visudo

nagios ALL = NOPASSWD: /etc/init.d/nagios

:wq

  1. ssh-keygen and ssh-copy-id across all nagios hosts so nagios can ssh from any nagios host to any other without a password as the nagios user.

  2. in /etc/nagios/nagios.cfg on all hosts you will need to add: under the main configuration loading up current data centres

    AUTOMATION ADD HERE

That should be all that is needed to get it going now refer to the script

nagios-failover's People

Watchers

Vahid Hedayati avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.