Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Alerts are sent when machine comes back online. Statuses turn purple …

…when cron isn't running
  • Loading branch information...
commit fdc63c2f047eb96167f93c331c408a70028c402d 1 parent b493069
Kevin Wojcik authored
View
4 config/email.conf
@@ -1,8 +1,4 @@
<root>
<address>kevinwojcik@dpengineering.org</address>
<address>8054514271@vtext.com</address>
-<address>hegarty@nees.ucsb.edu</address>
-<address>8054486169@vtext.com</address>
-<address>8057292180@vtext.com</address>
-<address>steidl@nees.ucsb.edu</address>
</root>
View
6 create
@@ -1,3 +1,8 @@
+CREATE TABLE meta (
+meta_id INTEGER PRIMARY KEY AUTOINCREMENT,
+last_checked INTEGER NOT NULL
+);
+
CREATE TABLE machine (
mach_id INTEGER PRIMARY KEY AUTOINCREMENT,
location TEXT NOT NULL,
@@ -118,6 +123,7 @@ CREATE TABLE updatewarning (
warning_id INTEGER PRIMARY KEY AUTOINCREMENT,
mach_id INTEGER NOT NULL,
time INTEGER NOT NULL,
+came_back INTEGER,
FOREIGN KEY (mach_id) REFERENCES machine(mach_id)
);
CREATE INDEX updatewarning_index ON updatewarning(mach_id, time);
View
4 css/tablethemes/blue/style.css
@@ -67,4 +67,8 @@ background-color: #8dbdd8;
.yellow {
width: 5px;
background-color: yellow !important;
+}
+.purple {
+ width: 5px;
+ background-color: purple !important;
}
View
28 main.php
@@ -9,22 +9,34 @@ function getSites($dir){
}
$dbh = new PDO($dir) or die("cannot open the database");
- $query = "SELECT * FROM machine";
+ $sql = 'SElECT * FROM meta ORDER BY last_checked DESC LIMIT 1';
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute(array());
+ $rows = $stmt->fetchAll();
+ $row = $rows[0];
+ $last_checked = $row[1];
+ $sql = "SELECT * FROM machine";
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute(array());
$yellow = 2 * 60 * 60;
$red = 4 * 60 * 60;
$timestamp = time();
- foreach ($dbh->query($query) as $row){
+ foreach ($stmt->fetchAll() as $row){
if(!in_array(intval($row[0]), $dontwatch)){
$diff = $timestamp - intval($row[4]);
echo '<tr class="site_clickable" id="',$row[0],'">';
- if($diff > $red)
- echo '<td class="red"></td>';
- elseif($diff > $yellow)
- echo '<td class="yellow"></td>';
- else
- echo '<td class="green"></td>';
+ if($timestamp - $last_checked > $yellow)
+ echo '<td class="purple"></td>';
+ else{
+ if($diff > $red)
+ echo '<td class="red"></td>';
+ elseif($diff > $yellow)
+ echo '<td class="yellow"></td>';
+ else
+ echo '<td class="green"></td>';
+ }
$uptime = floor($row[3]/86400).' days, '.sprintf("%02d",floor(($row[3]%86400)/3600)).':'.sprintf("%02d",floor(($row[3]%3600)/60));
echo '<td class="highlight">'.$row[1].'</td>';
View
10 nuke.sh
@@ -1,9 +1,13 @@
+mkdir /tmp/python
+mkdir /tmp/python/repo
+mkdir /tmp/tmp
+
rm /tmp/python/database*
rm /tmp/python/cleanup.sh
sqlite3 /tmp/python/database < create
cd /tmp/python/repo
-rm -rf * .git
-rm -rf * .git
+rm -rf /tmp/python/repo/* /tmp/python/repo/.git
+rm -rf /tmp/python/repo/* /tmp/python/repo/.git
git init
cd /tmp/tmp
-rm -rf *
+rm -rf /tmp/tmp/*
View
10 python/alerts.py
@@ -88,6 +88,16 @@ def execute(str):
warnings.append("Late update of %dhrs at %s" % (int((cur_time - last_update) / 3600), name))
str = 'INSERT INTO updatewarning (mach_id, time) VALUES (%d, %d)' % (mach_id, cur_time)
result = execute(str)
+ #Check if the machine came back...
+ else:
+ str = 'SELECT * FROM updatewarning WHERE mach_id=%d AND came_back IS NULL ORDER BY time DESC LIMIT 1' % mach_id
+ result = execute(str)
+
+ if(len(result) != 0):
+ update_id = updatewarningsql.getID(result[0])
+ str = 'UPDATE updatewarning SET came_back=1 WHERE warning_id=%d' % update_id
+ result = execute(str)
+ warnings.append("%s back online" % name)
str = 'SELECT * FROM disk WHERE mach_id=%d' % mach_id
disks = execute(str)
for disk in disks:
View
5 python/xml2db.py
@@ -56,6 +56,10 @@ def execute(str):
last_files = {}
+str = 'INSERT INTO meta (last_checked) VALUES (%d)' % time.time()
+result = execute(str)
+connection.commit()
+
print "listing site files... may take a long time"
file_listings = os.listdir(directory_path)
file_listings.sort()
@@ -402,3 +406,4 @@ def execute(str):
last_files[name] = xml_name
connection.commit()
connection.close()
+print "Done"
View
1  site.php
@@ -1,4 +1,5 @@
<?php
+ error_reporting(E_ALL ^ E_NOTICE);
include 'config/phpconf.php';
$mach_id = $_GET['mach_id'];
Please sign in to comment.
Something went wrong with that request. Please try again.