Added HTML5 Push-Notifications
This commit is contained in:
parent
681d24175a
commit
200046b0f1
|
@ -1,17 +1,18 @@
|
||||||
{
|
{
|
||||||
"name": "statusbot",
|
"name": "statusbot",
|
||||||
"description": "ctdo status bot",
|
"description": "ctdo status bot",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "3.4",
|
"connect-flash": "0.1.1",
|
||||||
"connect-flash": "0.1.1",
|
"express": "3.4",
|
||||||
"net-snmp": "1.1.8",
|
"jade": "0.35",
|
||||||
"redis": "0.8.5",
|
"moment": "2.3.1",
|
||||||
"underscore": "1.5.2",
|
"net-snmp": "1.1.8",
|
||||||
"jade": "0.35",
|
"node-notifier": "^4.2.3",
|
||||||
"socket.io": "0.9.16",
|
"redis": "0.8.5",
|
||||||
"moment": "2.3.1"
|
"socket.io": "0.9.16",
|
||||||
},
|
"underscore": "1.5.2"
|
||||||
"main": "index"
|
},
|
||||||
|
"main": "index"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
var express = require('express'),
|
var express = require('express'),
|
||||||
app = express(),
|
app = express(),
|
||||||
server = require('http').createServer(app),
|
server = require('http').createServer(app),
|
||||||
io = require('socket.io').listen(server);
|
io = require('socket.io').listen(server),
|
||||||
|
notifier = require('node-notifier');
|
||||||
var flash = require('connect-flash');
|
var flash = require('connect-flash');
|
||||||
var moment = require('moment');
|
var moment = require('moment');
|
||||||
var SnmpMac = require("./snmp-mac");
|
var SnmpMac = require("./snmp-mac");
|
||||||
|
@ -31,7 +32,7 @@ var spaceanswer = {
|
||||||
twitter: "@ctdo",
|
twitter: "@ctdo",
|
||||||
issue_mail: "server-admin@chaostreff-dortmund.de"
|
issue_mail: "server-admin@chaostreff-dortmund.de"
|
||||||
},
|
},
|
||||||
issue_report_channels: [ "issue_mail" ],
|
issue_report_channels: ["issue_mail"],
|
||||||
state: {
|
state: {
|
||||||
open: null,
|
open: null,
|
||||||
lastchange: 0,
|
lastchange: 0,
|
||||||
|
@ -41,23 +42,25 @@ var spaceanswer = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
sensors: {
|
sensors: {
|
||||||
power_consumption: [ {
|
power_consumption: [{
|
||||||
unit: "W",
|
unit: "W",
|
||||||
name: "mains power",
|
name: "mains power",
|
||||||
description: "overall power consumption from our space",
|
description: "overall power consumption from our space",
|
||||||
location: "basement",
|
location: "basement",
|
||||||
value: 0 } ]
|
value: 0}]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var simpleanswer = { state: "unknown", count: 0, names: [], lastchange: 0, power: 0 };
|
var simpleanswer = {state: "unknown", count: 0, names: [], lastchange: 0, power: 0};
|
||||||
var usercountanswer = { at: 0, current_value: 0, datapoints: [
|
var usercountanswer = {at: 0, current_value: 0, datapoints: [
|
||||||
{ at: 0, value: 0 }
|
{at: 0, value: 0}
|
||||||
]};
|
]};
|
||||||
|
|
||||||
var snmpMac = new SnmpMac("juni.ctdo.de", "ctdo23");
|
var snmpMac = new SnmpMac("juni.ctdo.de", "ctdo23");
|
||||||
var ippoll = new IpPoll("switch2.raum.ctdo.de", "195.160.169.30-120");
|
var ippoll = new IpPoll("switch2.raum.ctdo.de", "195.160.169.30-120");
|
||||||
var flukso = new Flukso("flukso.raum.ctdo.de", "/sensor/cf00e0b22230f4a8870af58f2b8719dd");
|
var flukso = new Flukso("flukso.raum.ctdo.de", "/sensor/cf00e0b22230f4a8870af58f2b8719dd");
|
||||||
|
|
||||||
|
var laststate = false;
|
||||||
|
|
||||||
snmpMac.on('done', function (res) {
|
snmpMac.on('done', function (res) {
|
||||||
simpleanswer.names = res;
|
simpleanswer.names = res;
|
||||||
simpleanswer.lastchange = new Date().getTime();
|
simpleanswer.lastchange = new Date().getTime();
|
||||||
|
@ -74,23 +77,55 @@ ippoll.on('doneState', function (state) {
|
||||||
spaceanswer.state.lastchange = new Date().getTime();
|
spaceanswer.state.lastchange = new Date().getTime();
|
||||||
simpleanswer.state = state;
|
simpleanswer.state = state;
|
||||||
simpleanswer.lastchange = spaceanswer.state.lastchange;
|
simpleanswer.lastchange = spaceanswer.state.lastchange;
|
||||||
io.sockets.emit('sdata', { data: simpleanswer });
|
io.sockets.emit('sdata', {data: simpleanswer});
|
||||||
});
|
});
|
||||||
|
|
||||||
flukso.on('done', function (num) {
|
flukso.on('done', function (num) {
|
||||||
simpleanswer.power = num;
|
simpleanswer.power = num;
|
||||||
spaceanswer.sensors.power_consumption[0].value = num;
|
spaceanswer.sensors.power_consumption[0].value = num;
|
||||||
io.sockets.emit('sdata', { data: simpleanswer });
|
io.sockets.emit('sdata', {data: simpleanswer});
|
||||||
});
|
});
|
||||||
|
|
||||||
io.configure(function () {
|
io.configure(function () {
|
||||||
io.set('log level', 0);
|
io.set('log level', 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
notifier.on('click', function (notifierObject, options) {
|
||||||
|
// Happens if `wait: true` and user clicks notification
|
||||||
|
});
|
||||||
|
|
||||||
|
notifier.on('timeout', function (notifierObject, options) {
|
||||||
|
// Happens if `wait: true` and notification closes
|
||||||
|
});
|
||||||
|
|
||||||
function work() {
|
function work() {
|
||||||
snmpMac.poll();
|
snmpMac.poll();
|
||||||
ippoll.pollCount();
|
ippoll.pollCount();
|
||||||
|
|
||||||
|
if (spaceanswer.state.open == true && laststate != true) {
|
||||||
|
laststate == true;
|
||||||
|
notifier.notify({
|
||||||
|
title: 'CTDO - Statusänderung',
|
||||||
|
message: 'Der Chaostreff Dortmund ist nun offen.',
|
||||||
|
icon: path.join('public/img/green.png'), // absolute path (not balloons)
|
||||||
|
sound: true, // Only Notification Center or Windows Toasters
|
||||||
|
wait: true // wait with callback until user action is taken on notification
|
||||||
|
}, function (err, response) {
|
||||||
|
// response is response from notification
|
||||||
|
});
|
||||||
|
} else if (spaceanswer.state.open == false && lasttaste != false) {
|
||||||
|
laststate == false;
|
||||||
|
|
||||||
|
notifier.notify({
|
||||||
|
title: 'CTDO - Statusänderung',
|
||||||
|
message: 'Der Chaostreff Dortmund ist nun geschlossen.',
|
||||||
|
icon: path.join('public/img/red.png'), // absolute path (not balloons)
|
||||||
|
sound: true, // Only Notification Center or Windows Toasters
|
||||||
|
wait: true // wait with callback until user action is taken on notification
|
||||||
|
}, function (err, response) {
|
||||||
|
// response is response from notification
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(work, 60000);
|
setInterval(work, 60000);
|
||||||
|
@ -111,7 +146,7 @@ app.configure('development', function () {
|
||||||
app.use(express.static(__dirname + '/public'));
|
app.use(express.static(__dirname + '/public'));
|
||||||
app.use(express.bodyParser());
|
app.use(express.bodyParser());
|
||||||
app.use(express.cookieParser('chaostreff'));
|
app.use(express.cookieParser('chaostreff'));
|
||||||
app.use(express.session({ cookie: { maxAge: 60000 }}));
|
app.use(express.session({cookie: {maxAge: 60000}}));
|
||||||
app.use(flash());
|
app.use(flash());
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,7 +184,3 @@ app.post('/form', routes.form);
|
||||||
app.get('/', routes.index);
|
app.get('/', routes.index);
|
||||||
|
|
||||||
server.listen(3000, 'localhost');
|
server.listen(3000, 'localhost');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue