Aller au contenu

Enregistrement de notification sur serveur sql


Messages recommandés

Posté(e) (modifié)

J'administre HC2 en 3 places. Je n'ai pas besoin d'informations sur le téléphone (push ou email), mais je veux savoir ce qui se passe.
Les utilisateurs ne veulent pas vérifier les notifications et n'ont pas le temps.
C'est pourquoi j'ai adopté d'anciens scripts qui enregistrent des notifications ( uniquement supprime les notifications moins importantes) et d'autres messages (p. Ex., Débogage) dans la base de données SQL.

Pour ceux qui s'intéressent au lien https://github.com/dr-boss/hc2-sql-log

 

et example (J'utilise deux temps (SQL et HC2) parce que HC2 ne fonctionne pas bien avec NTP

SQL Server time HC2 Time Source Level tMessage
2017-09-25 21:28:53 2017-09-25 21:28:46 S99 info 2017-09-25 21:28:26 - 91 - SceneToManyInstancesNotification!
2017-09-25 21:28:53 2017-09-25 21:28:46 S99 debug Delete notification
2017-09-25 21:28:53 2017-09-25 21:28:45 S99 alert 2017-09-25 19:41:38 - 95 - GenericDeviceNotification!
2017-09-25 21:27:27 2017-09-25 21:27:20 S99 debug Test
2017-09-25 21:26:08 2017-09-25 21:26:00 S99 debug Test
2017-09-25 21:19:55 2017-09-25 21:19:48 S99 debug Test
2017-09-25 21:01:03 2017-09-25 21:00:56 S152 notice time control
2017-09-25 20:01:03 2017-09-25 20:00:56 S152 notice time control
2017-09-25 19:01:03 2017-09-25 19:00:56 S152 notice time control
2017-09-25 18:01:02 2017-09-25 18:00:56 S152 notice time control
2017-09-25 17:01:02 2017-09-25 17:00:55 V100 info meteo data updated
2017-09-25 16:56:10 2017-09-25 16:56:04 S99 info 2017-09-25 16:47:33 - 91 - SceneToManyInstancesNotification!

 

Modifié par drboss
  • Upvote 1
Posté(e) (modifié)

Good job @drboss

thanks a lot

 

fibaro:args, startscene top top ;-)

 

Suggestion : 1 sql-syslog.lua

maybe possible : local hc2 = {

  name=....,

  name =.....}

 

for many HC2.

 

 

Modifié par pepite
Posté(e)

Yes i think about it, I will do it probably this weekend, because I made this code fast.... when the wife was asleep ;)

I things to take the name of HC2 from settings/info

  • Upvote 1
Posté(e) (modifié)

Okey, My wife and children were in the cinema today, so...

I doing new version.

1. no need create table for each HC2, table will created automatically on first connection (as name is used s/n without dash)

2. need to create only database (ex. fibaro) and use user with privilege CREATE TABLE in this database

3. scene check if connection exist, if not it stop copy, delete notifications until connection return but it not cache another message sending by calling this scene, yet :-)

On web site:

In fibaro_log.php is possible to select each connected HC2 to display last 100 row of message or to export all message in CSV file.

On HC2

sql-syslog.lua for send any message to sql server by fibaro:startScene with arg()

notification-rec-del.lua for send notification to sql server by call sql-syslog.lue and delete (according to selected conditions in scene)

 

Full description and files: 

 https://github.com/dr-boss/hc2-sql-log

 

 

 

sql1.PNG.8c5a8b2fe5055553fae8e2ba34d782cd.PNGsql2.PNG.249876972c0b5ebe837db80be3175fb2.PNGsql3.PNG.c3dc1cce3a0936876bec40878d993237.PNG

 

 

 

 

 

Modifié par drboss
  • Upvote 1
Posté(e)

just my opinion, because i m not able to write something  like you.

 

this should maybe work : but i have never test this
 

api.post("/globalVariables", {name = i, isEnum = true, value = v.value, enumValues = v.enumValue})

and for a lighten code but it's a personal choice :

this :

 

local secure = "no" -- Important!!! If you connect to sql server via internet use ssl on web server and change secure to 'yes'
local debug = "yes"

as :

local secure = false --true/false
local debug = true   -- true/false

 

for this :

if (secure) then http_type = "https" else http_type = "http" end

 

instead of :

if secure =="yes"

 

Posté(e)

@pepite Your corrections proposal is very good and right forimprove code quality. I wrote my code fast as a wife went to the cinema ;-) so it is messy (I had only 3h ;) ).
I wrote the code quickly without good formatting because I started one new HC2 far away from me and I am after spine surgery with mobility problem. And the customer has questions, new ideas, modifications etc. every moment ;-) This client is very important because is... my father, you understand what that means :D:D

As for the creation of the variable, all the time I forget that there is api.put, api.get, and I reused the verified version from the forum.

  • Upvote 1
×
×
  • Créer...