r106936 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106935‎ | r106936 | r106937 >
Date:10:36, 21 December 2011
Author:petrb
Status:deferred
Tags:tools 
Comment:
Included a script which parses the config and reload nagios
Modified paths:
  • /trunk/tools/nparser/fetch.sh (added) (history)
  • /trunk/tools/nparser/nparser.cpp (modified) (history)

Diff [purge]

Index: trunk/tools/nparser/fetch.sh
@@ -0,0 +1,42 @@
 2+#!/bin/sh
 3+#Written by benapetr@gmail.com
 4+
 5+temp=/tmp/parser_`date +%H%M%d%m`
 6+if [ -f parser ];then
 7+ if [ -d "$temp" ];then
 8+ rm -rf "$temp"
 9+ fi
 10+ if [ -d "$temp" ];then
 11+ echo "Fatal: can't clean $temp!"
 12+ exit 1
 13+ fi
 14+ mkdir "$temp"
 15+ wget https://labsconsole.wikimedia.org/wiki/Special:Ask/-5B-5BResource-20Type::instance-5D-5D/-3FInstance-20Name/-3FInstance-20Type/-3FProject/-3FImage-20Id/-3FFQDN/-3FLaunch-20Time/-3FPuppet-20Class/-3FModification-20date/-3FInstance-20Host/-3FNumber-20of-20CPUs/-3FRAM-20Size/-3FAmount-20of-20Storage/limit%3D500/format%3Djson -O $temp/novalist
 16+ if [ "`diff old/* $temp/*`" = "" ];then
 17+ echo OK
 18+ out=`./parser "$temp"`
 19+ if [ `echo $out | grep -c Error` -gt 0 ];then
 20+ echo Unable to parse the file
 21+ exit 0
 22+ fi
 23+ instances=`echo "$out" | awk '{ if ($0 ~ /SSH:/) exit } { print $0 }'`
 24+ list1=`echo "$out" | awk '{ if (p==1) print $0; p=2 } { if ($0 ~ /WWW:/) p=1 }'`
 25+ list2=`echo "$out" | awk '{ if (p==1) print $0; p=2 } { if ($0 ~ /SSH:/) p=1 }'`
 26+ for instance in `echo "$instances"`
 27+ do
 28+ cat default.cfg | sed "s/NAME/$instance/" > conf/$instance".cfg"
 29+ done
 30+ cp generic/* conf
 31+ cat hostgroup | sed "s/#web/$list1/" | sed "s/#SSH/$list2/" > conf/hostgroups_nagios2.cfg
 32+ cp /etc/nagios3/conf.d/* backup
 33+ rm -f /etc/nagios3/conf.d/*
 34+ mv conf/* /etc/nagios3/conf.d
 35+ service nagios3 reload
 36+ fi
 37+ mv "$temp"/* old
 38+ rm -rf "$temp"
 39+else
 40+ echo "Can't find binary file"
 41+ exit 1
 42+fi
 43+
Property changes on: trunk/tools/nparser/fetch.sh
___________________________________________________________________
Added: svn:eol-style
144 + native
Index: trunk/tools/nparser/nparser.cpp
@@ -32,8 +32,8 @@
3333 }
3434 string filepath( argv[1] );
3535 filepath = filepath + "/novalist";
36 - cout << filepath << endl;
37 - cout << "Parsing" << endl;
 36+ //cout << filepath << endl;
 37+ //cout << "Parsing" << endl;
3838 ifstream data( (char*) filepath.c_str() );
3939 string file;
4040 if (data.is_open())

Status & tagging log