diff --git a/node/notification.js b/node/notification.js new file mode 100644 index 0000000..fa98010 --- /dev/null +++ b/node/notification.js @@ -0,0 +1,54 @@ +var notifier = require('node-notifier'); + +var Notification = function (currentstate) { + + this.notificate = function () { + + 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 + }); + + if (currentstate == true && laststate != true) { + laststate == true; + notifier.notify({ + title: 'CTDO - Status', + 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 + }); + console.log("State changed to Open"); + } else if (currentstate == false && laststate != false) { + laststate == false; + notifier.notify({ + title: 'CTDO - Status', + 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 + }); + console.log("State changed to Close"); + } + }; +}; + +module.exports = Notification; + + + + + + + + + + + diff --git a/node/package.json b/node/package.json index fe52d43..e4e776e 100644 --- a/node/package.json +++ b/node/package.json @@ -9,6 +9,7 @@ "net-snmp": "1.1.8", "redis": "0.8.5", "underscore": "1.5.2", + "node-notifier": "^4.2.3", "jade": "0.35", "socket.io": "0.9.16", "moment": "2.3.1" diff --git a/node/statusbot.js b/node/statusbot.js index dcbbe78..0fbdd29 100644 --- a/node/statusbot.js +++ b/node/statusbot.js @@ -6,6 +6,7 @@ var flash = require('connect-flash'); var moment = require('moment'); var SnmpMac = require("./snmp-mac"); var IpPoll = require("./ip-poll"); +var Notification = require("./notification"); var Flukso = require("./flukso"); var routes = require("./routes"); var path = require('path'); @@ -57,6 +58,7 @@ var usercountanswer = { at: 0, current_value: 0, datapoints: [ var snmpMac = new SnmpMac("juni.ctdo.de", "ctdo23"); var ippoll = new IpPoll("switch2.raum.ctdo.de", "195.160.169.30-120"); var flukso = new Flukso("flukso.raum.ctdo.de", "/sensor/cf00e0b22230f4a8870af58f2b8719dd"); +var notification = new Notification(spaceanswer.state.open) snmpMac.on('done', function (res) { simpleanswer.names = res; @@ -91,6 +93,7 @@ io.configure(function () { function work() { snmpMac.poll(); ippoll.pollCount(); + notification.notificate(spaceanswer.state.open); } setInterval(work, 60000);