#!/usr/bin/perl ## ## Monolith written 082213 by Bowie J. Poag ## ## Monolith is a mechanism that allows regularly-scheduled scripts to be monitored remotely. For every entity (script, command, whatever) you want monitored, call this command. ## ## Usage: ./monolith.pl ## ## Example: /usr/local/bin/monolith.pl tripwire ## ## English: Make an entry in the Monolith database saying that Tripwire just ran. ## use Mysql; $monolithDBHandle=Mysql->connect('tmcpmonitordb','Monolith','xxxxx','xxxxxxxxxxx'); if ($monolithDBHandle==0) { print "Monolith: Unable to connect to DB.\n"; } $timeStamp=time; $hostName=`hostname`; chomp($hostName); $entityName=$ARGV[0]; $checkExistQuery=$monolithDBHandle->query("SELECT * FROM Entities WHERE entityName='$entityName' AND entityHostName='$hostName';"); while (@checkExist=$checkExistQuery->fetchrow_array) { $lastSeen=$checkExist[3]; $x++; } if ($x==0) ## No rows returned. Hmm. This means we're checking in for the first time, so, let's create a new entry for ourselves in the DB. { $updateMonolith=$monolithDBHandle->query("INSERT INTO Entities (entityName,entityHostName,entityLastSeen,entityFrozen) VALUES ('$entityName','$hostName','$timeStamp','0');"); } else { $updateMonolith=$monolithDBHandle->query("UPDATE Entities SET entityLastSeen='$timeStamp' WHERE entityName='$entityName' AND entityHostName='$hostName';"); } $entityDelta=$timeStamp-$lastSeen; $updateMonolith=$monolithDBHandle->query("INSERT INTO Events (timeStamp,hostName,reportingEntity,reportingDelta) VALUES ('$timeStamp','$hostName','$entityName','$entityDelta');");