Add telegram messaging for critical erros

This commit is contained in:
Ruben van de Ven 2019-11-11 20:34:33 +01:00
parent a99c2dcfbf
commit 750406b784
6 changed files with 59 additions and 24 deletions

View file

@ -28,6 +28,7 @@ import copy
from pythonosc.osc_server import AsyncIOOSCUDPServer
from hugvey.variablestore import VariableStore
import datetime
import telegram_handler
mainLogger = logging.getLogger("hugvey")
@ -102,6 +103,21 @@ class CentralCommand(object):
self.variableStore = VariableStore(varDb)
self.panopticon = Panopticon(self, self.config, self.voiceStorage)
# extra handlers so we get some info when AFK:
if 'telegram' in self.config and self.config['telegram']['token']:
fmt = '%(message)s\n<i>%(name)s:%(funcName)s (%(filename)s:%(lineno)d)</i>'
formatter = telegram_handler.HtmlFormatter(fmt=fmt, use_emoji = False)
for chat_id in self.config['telegram']['chat_ids']:
handler = telegram_handler.TelegramHandler(
token=self.config['telegram']['token'],
level=logging.CRITICAL,
chat_id=chat_id
)
handler.setFormatter(formatter)
logging.getLogger('hugvey').addHandler(handler)
logger.critical("Start server with Telegram integration")
# telegram_handler.formatter.use_emoji = True
def loadLanguages(self):

View file

@ -41,7 +41,7 @@ if __name__ == '__main__':
logger = logging.getLogger("hugvey")
# logger.setLevel(1) # to send all records to cutelog
socket_handler = logging.handlers.SocketHandler('127.0.0.1', 19996) # default listening address
logger.addHandler(socket_handler);
logger.addHandler(socket_handler)
logger.info("Start server")
command = CentralCommand(args=args, debug_mode=args.verbose > 0)

View file

@ -50,4 +50,7 @@ light:
off_intensity: 0
fade_duration_id: 37
story:
loop: true
loop: true
telegram:
token: null
chat_ids: []

View file

@ -1,6 +1,17 @@
var ws = new ReconnectingWebSocket( window.location.origin.replace('http', 'ws') +'/ws', null, { debug: false, reconnectInterval: 3000 } );
var seeme = true
var seeme = true;
var error_audio = new Audio('siren.wav');
var playSoundOnError = true;
var checkbox_sound = document.getElementById('play_sound_on_error')
checkbox_sound.addEventListener('change', (event) => {
if (event.target.checked) {
playSoundOnError = true;
} else {
playSoundOnError = false;
}
})
//request close before unloading
window.addEventListener('beforeunload', function(){
@ -50,30 +61,29 @@ class Timeline{
let endDate = new Date();
endDate.setMinutes(endDate.getMinutes()+20);
//follow the timeline or not if checkbox is checked
setTimeout(function(){
tl.setWindow(startDate, endDate);
}, 500);
this.moveInterval = setInterval(function(){
// skip movement if not visible
tl.moveTo(new Date());
}, 1000);
var checkbox = document.getElementById('follow_checkbox')
checkbox.addEventListener('change', (event) => {
if (event.target.checked) {
//follow the timeline or not if checkbox is checked
setTimeout(function(){
tl.setWindow(startDate, endDate);
}, 500);
this.moveInterval = setInterval(function(){
// skip movement if not visible
tl.moveTo(new Date());
}, 1000);
} else {
clearInterval(this.moveInterval)
}
})
var checkbox = document.getElementById('follow_checkbox')
checkbox.addEventListener('change', (event) => {
if (event.target.checked) {
this.moveInterval = setInterval(function(){
// skip movement if not visible
tl.moveTo(new Date());
}, 1000);
} else {
clearInterval(this.moveInterval)
}
});
ws.addEventListener( 'message', this);
@ -179,6 +189,9 @@ checkbox.addEventListener('change', (event) => {
this.eventDataSet.add({
content: msg['type'] +': ' + msg['info'] + (msg.hasOwnProperty('args')? ': '+msg['args'] : ""),
start: new Date(), type: 'point', group: hv_id, 'className': msg['lvlname']});
if (msg['lvlname'] == 'CRITICAL' && playSoundOnError) {
// error_audio.play();
}
break;
}
}

BIN
www/siren.wav Normal file

Binary file not shown.

View file

@ -76,7 +76,7 @@ font-size: 4.5pt;
border-color:darkred;
border-radius:15px;
}
#follow_button{
.buttons{
background: #669;
border-radius: 2px;
position: absolute;
@ -129,7 +129,10 @@ padding: 0 5px;
</style>
</head>
<body id='timeline'>
<div class='buttons'>
<label id='follow_button'><input id="follow_checkbox" type="checkbox" name="follow" value="follow" checked> Follow timeline</label>
<!-- <label id='sound_button'><input id="play_sound_on_error" type="checkbox" name="play_sound_on_error" value="play_sound_on_error" checked> Play sound on error</label>-->
</div>
<div id='line'></div>
<script type='application/javascript' src="/js/hugvey_timeline.js"></script>