Script to generate and deploy the config in command line

User / Community contributed content: modifications, patches, extensions, modules, scripts etc.

Script to generate and deploy the config in command line

Postby Tontonitch » Wed Jan 18, 2012 14:22

Hi,

I have some scripts which daily check/discover some resources and add the needed checks in the Nconf database, via the perl API.
After applying the changes to NConf, the configuration needs to be generated and deployed.
To automate that, I wrote a script which is launched in case of config changes.

The attached script is for NConf 1.3.0-0 (I have an old one for 1.2.6 if someone needs it).
full_config_generation.php.zip
(3.32 KiB) Downloaded 263 times


How-to:

1. Upload the script to <nconf dir>/bin, and change the execution rights:
Code: Select all
[icinga@SERVER bin]$ chmod ug+x /usr/local/nconf/bin/full_config_generation.php


2. Due to some permission restrictions, this script must be launched by the apache user, as if it is launched via the NConf web interface. To do that, you can use sudo whan logged as icinga/nagios.
So, set the sudo rule using visudo:
Code: Select all
[root@SERVER bin]$ visudo
[...]
icinga ALL=(apache) NOPASSWD: /usr/bin/php /usr/local/nconf/bin/full_config_generation.php
[...]


This will allow you to launch the script via:
Code: Select all
[icinga@SERVER bin]$ sudo -u apache php /usr/local/nconf/bin/full_config_generation.php


3. You can now launch the script. It will:
  • Generate config
  • Run syntax check
  • Deploy generated config

The output for these steps should be quite clear.

Exemple:

Code: Select all
 ==> Generate config <==

[ Initializing NConf perl-API (library version 0.3, written by A. Gargiulo) ]
[ Copyright (c) 2006 - 2012 Sunrise Communications AG, Zurich, Switzerland  ]

[INFO]  Starting generate_config script
[INFO]  Generating global config files
[INFO]  Generating config for Nagios-collector 'Default Icinga'
[INFO]  Ended generate_config script


 ==> Running syntax check <==

Default_collectorTotal Warnings: 0  -  Total Errors:   0

Icinga 1.5.1
Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org)
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 09-09-2011
License: GPL

Reading configuration data...
   Read main config file okay...
Processing object config file '/usr/local/nconf/temp/global/timeperiods.cfg'...
Processing object config file '/usr/local/nconf/temp/global/contacts.cfg'...
Processing object config file '/usr/local/nconf/temp/global/misccommands.cfg'...
Processing object config file '/usr/local/nconf/temp/global/checkcommands.cfg'...
Processing object config file '/usr/local/nconf/temp/global/host_templates.cfg'...
Processing object config file '/usr/local/nconf/temp/global/service_templates.cfg'...
Processing object config file '/usr/local/nconf/temp/global/contactgroups.cfg'...
Processing object config file '/usr/local/nconf/temp/Default_collector/service_dependencies.cfg'...
Processing object config file '/usr/local/nconf/temp/Default_collector/host_dependencies.cfg'...
Processing object config file '/usr/local/nconf/temp/Default_collector/advanced_services.cfg'...
Processing object config file '/usr/local/nconf/temp/Default_collector/services.cfg'...
Processing object config file '/usr/local/nconf/temp/Default_collector/servicegroups.cfg'...
Processing object config file '/usr/local/nconf/temp/Default_collector/hosts.cfg'...
Processing object config file '/usr/local/nconf/temp/Default_collector/hostgroups.cfg'...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking services...
        Checked 1564 services.
Checking hosts...
        Checked 166 hosts.
Checking host groups...
        Checked 19 host groups.
Checking service groups...
        Checked 0 service groups.
Checking contacts...
        Checked 11 contacts.
Checking contact groups...
        Checked 5 contact groups.
Checking service escalations...
        Checked 0 service escalations.
Checking service dependencies...
        Checked 0 service dependencies.
Checking host escalations...
        Checked 0 host escalations.
Checking host dependencies...
        Checked 0 host dependencies.
Checking commands...
        Checked 180 commands.
Checking time periods...
        Checked 7 time periods.
Checking modules...
        Checked 0 modules.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check


 ==> Deploy generated config <==
local
 * extract config OK
  - PHP copy: OK
       temporary copy(/usr/local/nconf/output/NagiosConfig.tgz, /tmp/nconf_extracted/NagiosConfig.tgz)
  - system call OK
       gunzip -f /tmp/nconf_extracted/NagiosConfig.tgz
  - system call OK
       tar -xf /tmp/nconf_extracted/NagiosConfig.tar -C /tmp/nconf_extracted/
  - PHP unlink: OK
        remove temporary file(/tmp/nconf_extracted/NagiosConfig.tar)
 * copy collector config OK
  - PHP copy: OK
       recursive copy(/tmp/nconf_extracted/Default_collector/, /usr/local/icinga/etc/objects/Default_collector/)
 * copy global config OK
  - PHP copy: OK
       recursive copy(/tmp/nconf_extracted/global/, /usr/local/icinga/etc/objects/global/)
 * copy ido2db.cfg OK
  - PHP copy: OK
       copy(/tmp/nconf_extracted/static_cfg/ido2db.cfg, /usr/local/icinga/etc/ido2db.cfg)
  - system call OK
       sudo -u root /etc/init.d/ido2db restart Stopping ido2db: done.Starting ido2db: done.
 * copy idomod.cfg OK
  - PHP copy: OK
       copy(/tmp/nconf_extracted/static_cfg/idomod.cfg, /usr/local/icinga/etc/idomod.cfg)
 * copy cgi.cfg OK
  - PHP copy: OK
       copy(/tmp/nconf_extracted/static_cfg/cgi.cfg, /usr/local/icinga/etc/cgi.cfg)
 * copy cgiauth.cfg OK
  - PHP copy: OK
       copy(/tmp/nconf_extracted/static_cfg/cgiauth.cfg, /usr/local/icinga/etc/cgiauth.cfg)
 * copy icinga.cfg OK
  - PHP copy: OK
       copy(/tmp/nconf_extracted/static_cfg/icinga.cfg, /usr/local/icinga/etc/icinga.cfg)
  - system call OK
       sudo -u root /etc/init.d/icinga reload Running configuration check...OKReloading icinga configuration...done
[icinga@SERVER bin]$


BR,
Yannick
User avatar
Tontonitch
NConf addict
NConf addict
 
Posts: 254
Joined: Fri May 07, 2010 10:14
Location: Thionville, France

Re: Script to generate and deploy the config in command line

Postby Tontonitch » Wed Jan 18, 2012 14:31

@Angelo,Fabian
This script has been pushed in my NConf repository fork, under the 'feature_commandline_generateconfig' branch.
Commit: https://github.com/Tontonitch/NConf/com ... e7bb71eabb
I have not created a pull request yet, as you may have another approach.
But feel free to pick up if you want ;)
User avatar
Tontonitch
NConf addict
NConf addict
 
Posts: 254
Joined: Fri May 07, 2010 10:14
Location: Thionville, France

Re: Script to generate and deploy the config in command line

Postby agargiulo » Wed Jan 18, 2012 15:28

Thanks. We're going through your contributions one by one and evaluating a possible merge. It's gonna take a bit though, because we need to double check stuff with eachother...

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


Return to Contributions

Who is online

Users browsing this forum: No registered users and 1 guest

cron