Skip to content

Commit

Permalink
add relay tohost monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jun 23, 2015
1 parent c501f66 commit 3ad9431
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
7 changes: 4 additions & 3 deletions modules/highcharts/highcharts2
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ mkdir -p $dir/tmp/highcharts
rm -rf $dir/tmp/highcharts/*

# hosts
name=$(sqlite3 $dir/dbf/hosts.db "SELECT name FROM hosts")
name="$(sqlite3 $dir/dbf/hosts.db "SELECT name FROM hosts")"
for i in $name; do
if base=$(sqlite3 $dir/db/$i.sql "select strftime('%s', time),value FROM def;") ;
rom=$(sqlite3 $dir/dbf/hosts.db "SELECT rom FROM hosts WHERE name='$i'")
if base=$(sqlite3 $dir/db/$rom.sql "select strftime('%s', time),value FROM def;") ;
then
#middle=$(printf "$base %s\n" | awk -F "|" '{printf "["}{ printf "%3.0f",($1+3600)*1000}{printf ","}{printf "%3.3f", $2}{print "]," }')
middle=$(printf "$base %s\n" | awk -F "|" '{printf "["}{ printf "%3.0f",($1)*1000}{printf ","}{printf "%3.3f", $2}{print "]," }')
echo -e "[ ${middle%?} ]" > $dir/tmp/highcharts/$i.json
echo -e "[ ${middle%?} ]" > $dir/tmp/highcharts/$rom.json
else
echo "cannot read base"
fi
Expand Down
12 changes: 7 additions & 5 deletions modules/hosts/host_read
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ date=`date +%y%m%d-%H%M`
if ip=$(sqlite3 $dir/dbf/hosts.db "SELECT ip FROM hosts WHERE type='httpping'")
then
for i in $ip; do
name=$(sqlite3 $dir/dbf/hosts.db "SELECT name FROM hosts WHERE ip='$i'")
rom=$(sqlite3 $dir/dbf/hosts.db "SELECT rom FROM hosts WHERE ip='$i'")
name=$(sqlite3 $dir/dbf/hosts.db "SELECT rom FROM hosts WHERE ip='$i'")
wynik=$(httping -m -c 1 $i)
if [ "$wynik" != "-1" ] && [ -n "$wynik" ]
then
sqlite3 $dir/db/$name.sql "INSERT OR IGNORE INTO def (value) VALUES ('$wynik');"
sqlite3 $dir/db/$rom.sql "INSERT OR IGNORE INTO def (value) VALUES ('$wynik');"
sqlite3 $dir/dbf/hosts.db "UPDATE hosts SET last='$wynik', status='OK' WHERE ip='$i'"
$dir/modules/
else
sqlite3 $dir/db/$name.sql "INSERT OR IGNORE INTO def (value) VALUES ('$wynik');"
sqlite3 $dir/db/$rom.sql "INSERT OR IGNORE INTO def (value) VALUES ('$wynik');"
sqlite3 $dir/dbf/hosts.db "UPDATE hosts SET last='0', status='error' WHERE ip='$i'"
echo fail
fi
Expand All @@ -29,13 +30,14 @@ if ip=$(sqlite3 $dir/dbf/hosts.db "SELECT ip FROM hosts WHERE type='ping'")
then
for i in $ip; do
name=$(sqlite3 $dir/dbf/hosts.db "SELECT name FROM hosts WHERE ip='$i'")
rom=$(sqlite3 $dir/dbf/hosts.db "SELECT rom FROM hosts WHERE ip='$i'")
wynik=$(fping $i -e | awk -F"(" '{ print $2}' |sed 's/.\{3\}$//')
if [ -n "$wynik" ]
then
sqlite3 $dir/db/$name.sql "INSERT OR IGNORE INTO def (value) VALUES ('$wynik');"
sqlite3 $dir/db/$rom.sql "INSERT OR IGNORE INTO def (value) VALUES ('$wynik');"
sqlite3 $dir/dbf/hosts.db "UPDATE hosts SET last='$wynik', status='OK' WHERE ip='$i'"
else
sqlite3 $dir/db/$name.sql "INSERT OR IGNORE INTO def (value) VALUES ('$wynik');"
sqlite3 $dir/db/$rom.sql "INSERT OR IGNORE INTO def (value) VALUES ('$wynik');"
sqlite3 $dir/dbf/hosts.db "UPDATE hosts SET last='0', status='error' WHERE ip='$i'"
echo fail
fi
Expand Down
16 changes: 11 additions & 5 deletions modules/hosts/html/hosts_settings.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
<?php

$rand=substr(rand(), 0, 10);
$host_name = isset($_POST['host_name']) ? $_POST['host_name'] : '';
$host_ip = isset($_POST['host_ip']) ? $_POST['host_ip'] : '';
$host_id = isset($_POST['host_id']) ? $_POST['host_id'] : '';
$host_type = isset($_POST['host_type']) ? $_POST['host_type'] : '';

?>
<div class="panel panel-default">
<div class="panel-heading">Monitoring</div>

<?php // SQlite
$host_add1 = isset($_POST['host_add1']) ? $_POST['host_add1'] : '';
if (!empty($host_name) && !empty($host_ip) && ($host_add1 == "host_add2") ){
$db = new PDO('sqlite:dbf/hosts.db');
$host_name=host_ . $host_name;
$host_name=str_replace(".","",$host_name);
$db->exec("INSERT OR IGNORE INTO hosts (name, ip, type) VALUES ('$host_name', '$host_ip', '$host_type')") or die ("cannot insert to DB" );
$db->exec("INSERT OR IGNORE INTO hosts (name, ip, rom, type) VALUES ('$host_name', '$host_ip', '$host_name', '$host_type')") or die ("cannot insert to DB" );
$dbnew = new PDO("sqlite:db/$host_name.sql");
$dbnew->exec("CREATE TABLE def (time DATE DEFAULT (datetime('now','localtime')), value INTEEGER)");
$dbnew==NULL;
header("location: " . $_SERVER['REQUEST_URI']);
exit();
}
elseif ($host_add1 == "host_add2") { echo " Please input name and IP"; }
?>
elseif ($host_add1 == "host_add2") { ?>
<div class="panel-body">
<span class="label label-danger">Please input name and IP</span>
</div>
<?php
}
?>


<?php // SQLite - del
Expand All @@ -36,8 +44,6 @@
}
?>

<div class="panel panel-default">
<div class="panel-heading">Monitoring</div>
<table class="table table-striped">
<thead><tr><th></th><th>Name</th><th>IP / Name</th><th>Type</th><th>Add / Rem</tf></tr></thead>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion modules/sensors/html/sensors.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
$db->exec("INSERT OR IGNORE INTO relays (name, rom, ip, type) VALUES ('wi_relay_$name','$id_rom_new','$ip', '$type' )") or die ("cannot insert relays to DB" );
//host for monitoring
$dbhost = new PDO("sqlite:dbf/hosts.db");
$dbhost->exec("INSERT OR IGNORE INTO hosts (name, ip, rom, type) VALUES ('wi_relay_$name', '$ip', 'host_$id_rom_new', 'ping')") or die ("cannot insert host to DB" );
$dbhost->exec("INSERT OR IGNORE INTO hosts (name, ip, rom, type) VALUES ('host_wifi_relay_$name', '$ip', 'host_$id_rom_new', 'ping')") or die ("cannot insert host to DB" );
$dbnew = new PDO("sqlite:db/host_$id_rom_new.sql");
$dbnew->exec("CREATE TABLE def (time DATE DEFAULT (datetime('now','localtime')), value INTEEGER)");
$dbnew==NULL;
Expand Down

0 comments on commit 3ad9431

Please sign in to comment.