Page 1 of 1 1
Topic Options
#75059 - 2003-05-19 05:30 PM Checking powerchute logs enterprise wide
mvdw Offline
Starting to like KiXtart

Registered: 2001-05-01
Posts: 124
Loc: Voorburg, Netherlands
Hi there,

It has been a while since I have last posted here but it's really nice to know you are still keeping up the excellent job you are doing here. Since I practically learned all about scripting (in kix) from you guys I figure that anything usefull I create should be posted here.

I had to find someway to check all of the powerchute logs for failing UPS's. I have used a framework that allows me to connect to a bunch of servers from a file called "connect.ini" and it creates an administrative mapping to that server based on userid / password combinations from that same connect.ini
The reason I had to do this is that I manage an environment that does not support nameresolving, as well as regularly changes admin passwords. If you have the luxury to manage an environment without these restrictions you would be able to use a lot less code for all the connections but anyway... on with the business.
The script requires the connect.ini in the same directory as the script and it should be in the following form :
code:
[admins]
administrator;NewAdminPazzword;TheNewOne=1
administrator;OldAdminpazzword;TheOldOne=1

[names]
Myserver1=192.168.0.1
Myserver2=192.168.0.2
Myserver3=192.168.0.3
Myserver4=192.168.0.4

The [admins] part entries need to be of the form :
userid ; password ; description =1

the names part speaks for itsself I guess.

Then if you run the following script :
code:
 
cls
break on

global $names[1]
global $ips[1]
global $loggedlines[0]
global $battfailures[0]
global $testfailures[0]
global $commfailures[0]
$msgs = 300000,300100,300200,300201,300202,300203,
300204,300205,300206,300300,300301,300400,
301000,301300,301301,301302,301303,301304,
301400,301500,301600,310001,310002,310101,
310102,310300,310400,310500,310600,310700,
100900,100402,100200,100400,100401,100403

$commfailure = 300000
$commsuccess = 100200
$testfailure = 300200,300201,300203,300205
$testsuccess = 100400,100401,100402,100403
$battfailure = 301600
$battsuccess = 100900
$listlen = 0
$loopctr = 0
$connected = 0
$log = "@curdir\allserversups.log"
$crlf = chr(13) + chr(10)
$ini = "@curdir\connect.ini"

;The worldonly option exludes servers based on the existence of a defined string (see readserverlist subroutine)
;setting it to 0 ensures all servers in the connect.ini are processed.
$worldonly = 0
$connshare = "c$"

if open (1,$log,5) = 0
logline("====================================================================================")
logline("Script started at @time @date by @userid (@fullname)")
logline("------------------------------------------------------------------------------------")
"====================================================================================" ?
"Script started at @time @date by @userid (@fullname)" ?
"------------------------------------------------------------------------------------" ?

"Reading serverlist ... "
gosub readserverlist
"Done." ??
for $loopctr = 0 to $listlen
$ipselect = $ips[$loopctr]
$servername = $names[$loopctr]
"Connecting to $servername ... "
gosub connect
if $connected
"Done." ?
"Processing $servername ... "
logline("Loglines of interest for server $servername :")
gosub actionserver
"Done." ?
else
"Failed." ?
logline("connection failed to server $servername !")
endif
next

logline("")
logline("Summary report :")
if ubound($commfailures) > 0
redim preserve $commfailures[(ubound($commfailures) - 1)]
logline("")
logline(" The script found communication problems between the server and UPS on these servers :")
for each $commfailedserver in $commfailures
logline(" - $commfailedserver")
next
endif
if ubound($battfailures) > 0
redim preserve $battfailures[(ubound($battfailures) - 1)]
logline("")
logline(" The script found UPS battery problems on these servers :")
for each $battfailedserver in $battfailures
logline(" - $battfailedserver")
next
endif
if ubound($testfailures) > 0
redim preserve $testfailures[(ubound($testfailures) - 1)]
logline("")
logline(" The script found UPS self test problems on these servers :")
for each $testfailedserver in $testfailures
logline(" - $testfailedserver")
next
endif

logline("------------------------------------------------------------------------------------")
logline("Script Finished at @time @date")
logline("====================================================================================")
else
? "Unable to open/create logfile !!!"
endif
"-------------------------------------------------------------------------------------" ?
"Script finished at @time @date by @userid (@fullname)" ?
"=====================================================================================" ?

use v: /delete
? "Press any key to return."
get $k
exit

;=====================================================================================
:readserverlist
dim $i,$ii, $tempnames[1]

$tempnames = split((readprofilestring($ini,"names","")),chr(10))
$listlen = ubound($tempnames) - 1
$ii = 0
redim $ips[$listlen]
redim $names[$listlen]
for $i = 0 to $listlen
if $worldonly
if not instr($tempnames[$i],"fe1") ;This excludes all servers that contain the string "fe1"
$ips[$ii] = readprofilestring($ini,"names",$tempnames[$i])
$names[$ii] = $tempnames[$i]
$ii = $ii + 1
redim preserve $ips[$ii]
redim preserve $names[$ii]
endif
else
$ips[$i] = readprofilestring($ini,"names",$tempnames[$i])
$names[$i] = $tempnames[$i]
endif
next
$listlen = ubound($names)
return
;=====================================================================================

;=====================================================================================
:connect
dim $adminstring, $tempstring, $adminname, $adminpw, $admindesc
$connected = 0
use v: /delete
for each $adminstring in split(readprofilestring($ini,"admins",""),chr(10))
if $adminstring
$tempstring = split($adminstring, ";")
$adminname = $tempstring[0]
$adminpw = $tempstring[1]
$admindesc = $tempstring[2]
use v: "\\$ipselect\$connshare" /user:$adminname /password:$adminpw
select
case @error = 0
$connected = 1
return
case 1
$connected = 0
endselect
endif
next
return
;=====================================================================================

;=====================================================================================
:actionserver

;Read the contents of the powerchute log and place all lines since the latest occurence
;of "Powerchute PLUS verion x.x started" in an array called loggedlines

if open (4,"v:\program files\pwrchute\pwrchute.log") = 0
$linepos = 0
$lineread = readline(4)
do
if (instr ($lineread, "PowerChute PLUS")) AND (instr ($lineread, "started"))
redim $loggedlines[0]
$linepos = 0
endif
$loggedlines[$linepos] = $lineread
$linepos = $linepos + 1
redim preserve $loggedlines[$linepos]
$lineread = readline(4)
until @error <> 0

;cutting of the last line since that is always blank in powerchute logfiles

redim preserve $loggedlines[($linepos -1)]
;Check the array of logged lines for error messages and recovery of these error messages.
;Log error lines to verbose section of report and create summarization arrays.

$commfailed = 0
$battfailed = 0
$testfailed = 0

for $i = 1 to ubound($loggedlines)
$currline = $loggedlines[$i]
$errlistcount = 0
while ($errlistcount < ubound($msgs)) AND (instr($currline,$msgs[$errlistcount])=0)
$errlistcount = $errlistcount + 1
loop
if $errlistcount < ubound($msgs)
logline($currline)
endif

select
case instr($currline,$commfailure)
$commfailed = $commfailed + 1
case instr($currline,$commsuccess)
if $commfailed > 0
$commfailed = $commfailed - 1
endif
case instr($currline,$battfailure)
$battfailed = $battfailed + 1
case instr($currline,$battsuccess)
if $battfailed > 0
$battfailed = $battfailed - 1
endif
case (instr($currline,$testfailure[0])) OR (instr($currline,$testfailure[1])) OR (instr($currline,$testfailure[2])) OR (instr($currline,$testfailure[3]))
$testfailed = $testfailed + 1
case (instr($currline,$testsuccess[0])) OR (instr($currline,$testsuccess[1])) OR (instr($currline,$testsuccess[2])) OR (instr($currline,$testsuccess[3]))
if $testfailed > 0
$testfailed = $testfailed - 1
endif
endselect
next

if $commfailed > 0
$commfailures[ubound($commfailures)] = $servername
redim preserve $commfailures[(ubound($commfailures) + 1)]
endif

if $battfailed > 0
$battfailures[ubound($battfailures)] = $servername
redim preserve $battfailures[(ubound($battfailures) + 1)]
endif

if $testfailed > 0
$testfailures[ubound($testfailures)] = $servername
redim preserve $testfailures[(ubound($testfailures) + 1)]
endif

else
logline("Error opening logfile: @serror")
endif
if close(4) = 0 endif
return


Function logline($linetolog)
if writeline(1,"" + $linetolog + $crlf) = 0 endif
endfunction

It will then create an output file called allserversups.log. This log file contains an overview of all 'interesting' messages from the UPS log per server. It also analyzes these messages and creates a summary of Communcations- Battery- and self-test related problems.

An example output is :
code:
 ====================================================================================
Script started at 17:23:17 2003/05/19 by MyUserID (MvdW)
------------------------------------------------------------------------------------
Loglines of interest for server MyServer1 :
100200 05/11/03 14:25:03 Communication established
Loglines of interest for server MyServer2 :
100200 04/23/03 07:13:02 Communication established
301600 04/25/03 21:41:09 UPS battery needs replacing
300205 04/25/03 21:41:18 Self-test at UPS failed
100900 05/09/03 21:41:22 UPS batteries no longer need replacing
301600 05/09/03 21:41:24 UPS battery needs replacing
300205 05/09/03 21:41:30 Self-test at UPS failed
300301 05/19/03 08:31:15 UPS battery is discharged: 000.0
300301 05/19/03 08:41:22 UPS battery is discharged: 005.0
300301 05/19/03 08:41:45 UPS battery is discharged: 006.0
Loglines of interest for server MyServer3 :
300000 03/25/03 23:16:37 Unable to communicate with UPS
Loglines of interest for server MyServer4 :
300000 05/16/03 14:16:23 Unable to communicate with UPS
Loglines of interest for server MyServer5 :
100200 05/08/03 23:29:45 Communication established
301600 05/13/03 12:53:47 UPS battery needs replacing
300205 05/13/03 12:53:56 Self-test at UPS failed

Summary report :

The script found communication problems between the server and UPS on these servers :
- MyServer3
- MyServer4

The script found UPS battery problems on these servers :
- MyServer2
- MyServer5

The script found UPS self test problems on these servers :
- MyServer2
- MyServer5
------------------------------------------------------------------------------------
Script Finished at 17:24:05 2003/05/19
====================================================================================

Well, any comments are welcome ofcourse. I bet there are better ways of doing some of these routines. Especially the lack of functions is a bit old-style, but hey ... it works !
Also the parsing of the logfiles would probably be done with 2 lines of perl in stead of all this kixing but then again.... it works !

Anyhow let me know what you think, especially if it was (partly) of use to you.

Cheers !

ps I am working on some sort of XML output to integrate it into our existing monitoring framework. But then again you could modify it anyway you'd like, even to generate html and run this script every night ??? whatever..

[ 19. May 2003, 17:33: Message edited by: mvdw ]
_________________________
rgrds, Maarten

Top
#75060 - 2003-05-19 05:46 PM Re: Checking powerchute logs enterprise wide
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Why don't you set up email alerts with PowerChute? That would give you near-instantaneous notification of any UPS-related problem.
_________________________
There are two types of vessels, submarines and targets.

Top
#75061 - 2003-05-19 05:48 PM Re: Checking powerchute logs enterprise wide
mvdw Offline
Starting to like KiXtart

Registered: 2001-05-01
Posts: 124
Loc: Voorburg, Netherlands
True,

but that will not give me an all-inclusive overview of all servers and their status...

and it is not as much fun :-)
_________________________
rgrds, Maarten

Top
#75062 - 2003-05-19 05:56 PM Re: Checking powerchute logs enterprise wide
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
fun is good reason! [Big Grin]
_________________________
!

download KiXnet

Top
#75063 - 2003-05-20 10:51 AM Re: Checking powerchute logs enterprise wide
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
The danged PowerChute Business Edition is limited... then you'll have to *pay* to get your UPS's working.. blah :/
_________________________
The tart is out there

Top
#75064 - 2003-05-20 11:17 PM Re: Checking powerchute logs enterprise wide
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I monitor differing brands of UPSs, servers, switches, routers etc. with SNMP. I trend data with MRTG and use Whatsup Gold to monitor and notify.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1067 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.052 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org