2 İşlemeler e4fd7790ac ... 4f61a79ad5

Yazar SHA1 Mesaj Tarih
  adri 4f61a79ad5 unignore Commands 3 hafta önce
  adri a29da0eb49 add proper logger to summary 3 hafta önce

+ 16 - 0
.gitignore

@@ -0,0 +1,16 @@
+.env
+*.bak
+Masks/
+Media/
+Plugins/
+XML.bak/
+XML/
+backup/
+builder/
+*.disabled
+*.old
+old/
+sounds/
+summary/*.csv
+summary/db/
+

+ 2 - 0
Commands/Alerts Off.bat

@@ -0,0 +1,2 @@
+REM ispy-internal
+ALERTOFF

+ 2 - 0
Commands/Alerts On.bat

@@ -0,0 +1,2 @@
+REM ispy-internal
+ALERTON

+ 2 - 0
Commands/All Off.bat

@@ -0,0 +1,2 @@
+REM ispy-internal
+ALLOFF

+ 2 - 0
Commands/All On.bat

@@ -0,0 +1,2 @@
+REM ispy-internal
+ALLON

+ 2 - 0
Commands/Apply Schedule.bat

@@ -0,0 +1,2 @@
+REM ispy-internal
+APPLYSCHEDULE

+ 2 - 0
Commands/Record Off.bat

@@ -0,0 +1,2 @@
+REM ispy-internal
+RECORDINGOFF

+ 2 - 0
Commands/Record on Alert.bat

@@ -0,0 +1,2 @@
+REM ispy-internal
+RECORDONALERTON

+ 2 - 0
Commands/Record on Detect.bat

@@ -0,0 +1,2 @@
+REM ispy-internal
+RECORDONDETECTON

+ 2 - 0
Commands/Restart Agent.bat

@@ -0,0 +1,2 @@
+REM ispy-internal
+RESTART

+ 2 - 0
Commands/Run Storage Mgmt.bat

@@ -0,0 +1,2 @@
+REM ispy-internal
+RUNSTORAGEMGMT

+ 2 - 0
Commands/Snapshot.bat

@@ -0,0 +1,2 @@
+REM ispy-internal
+SNAPSHOT

+ 2 - 0
Commands/Start Record.bat

@@ -0,0 +1,2 @@
+REM ispy-internal
+RECORD

+ 2 - 0
Commands/Stop Cloud Uploads.bat

@@ -0,0 +1,2 @@
+REM ispy-internal
+STOPCLOUDUPLOADS

+ 2 - 0
Commands/Stop Record.bat

@@ -0,0 +1,2 @@
+REM ispy-internal
+RECORDSTOP

+ 2 - 0
Commands/Stop Streaming.bat

@@ -0,0 +1,2 @@
+REM ispy-internal
+RTMPSTOP

+ 2 - 0
Commands/_Example.bat

@@ -0,0 +1,2 @@
+REM ispy-internal
+BROADCAST 'Example command - see Commands/readme.txt to add your own'

+ 3 - 0
Commands/fix_archive_perms.sh

@@ -0,0 +1,3 @@
+#!/bin/bash
+find /mnt/rshare/agent-archive -type d -exec chmod og+rwx '{}' \;
+find /mnt/rshare/agent-archive -type f -exec chmod og+rw '{}' \;

+ 49 - 0
Commands/readme.txt

@@ -0,0 +1,49 @@
+To add your own commands to the list create a new file in the Commands directory
+
+You can execute internal commands by adding a new .bat file and adding a remark at the top of the file. For example to switch all internal cameras off and start recording all external cameras you could do:
+
+
+REM ispy-internal
+switchon&group=external
+switchoff&group=internal
+RECORD
+BROADCAST 'external cameras are on and recording'
+
+(This uses groups - so you'd need to setup your internal/ external cameras with group names on the general tab when you edit them )
+
+list of available commands:
+
+allon
+alloff
+applyschedule
+stopclouduploads
+recordondetecton
+recordonalerton
+recordingoff
+record
+recordstop
+alerton
+alertoff
+snapshot
+alert
+switchon
+switchoff
+
+more: https://www.ispyconnect.com/docs/agent/api
+
+
+You can use these commands on their own, with a group or by passing in an object type and and object id:
+
+-- specify ot=2 for a camera or ot=1 for a microphone and pass in an object id - you can find the object id (oid) on the server object list on the web portal (second column).
+switchon&ot=2&oid=1 
+
+-- specify a group name
+switchon&group=garage
+
+-- apply to all objects
+switchon
+
+To run an executable file say to open a garage door or something you'd leave off the REM ispy-internal command and just create a regular .bat (or .sh on linux/ osx) file like
+
+start "c:\program files\acme garage door" opensesame.exe
+

+ 9 - 0
Commands/save_summary.sh

@@ -0,0 +1,9 @@
+#!/bin/bash
+
+# Escape arguments
+id=$(sqlite3 :memory: <<< ".shell echo '$1'")
+file=$(sqlite3 :memory: <<< ".shell echo '$2'")
+summary=$(sqlite3 :memory: <<< ".shell echo '$3'")
+
+# Insert the row
+sqlite3 /agent/Media/XML/fileDB.db3 "INSERT INTO AgentSummary (id, file, summary) VALUES ('$id', '$file', '$summary');"

+ 14 - 3
summary/main.py

@@ -2,6 +2,8 @@ import sqlite3
 import json
 import os
 import paho.mqtt.client as mqtt
+import logging
+
 
 DB_FILE = os.getenv('DB_FILE', 'agent-summary.db3')
 MQTT_HOST = os.getenv('MQTT_HOST', 'iris.dgtlu.net')
@@ -9,6 +11,15 @@ MQTT_TOPIC = os.getenv('MQTT_TOPIC','agent/summary')
 MQTT_USER = os.getenv('MQTT_USER','agent')
 MQTT_PASS = os.getenv('MQTT_PASS','agent')
 
+logger = logging.get("__name__")
+debug = os.getenv("DEBUG", "")
+if debug:
+    logger.setLevel(logging.DEBUG)
+else
+    logger.setLevel(logging.INFO)
+logger.addHandler(logging.StreamHandler())
+
+
 def db_init():
     conn = sqlite3.connect(DB_FILE)
     c = conn.cursor()
@@ -35,9 +46,9 @@ def db_save_input(conn: sqlite3.Connection, json_string):
 def mqtt_init() -> mqtt:
     def on_connect(mqt_client, userdata, flags, rc, properties):
         if rc == 0:
-            print("Connected to MQTT Broker!")
+            logger.info("Connected to MQTT Broker!")
         else:
-            print("Failed to connect, return code %d\n", rc)
+            logger.error("Failed to connect, return code %d\n", rc)
 
     client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
     client.on_connect = on_connect
@@ -48,7 +59,7 @@ def mqtt_init() -> mqtt:
 
 def mqtt_subscribe(client: mqtt, db_conn: sqlite3.Connection):
     def on_message(mqt_client, userdata, msg):
-        print(f"Received `{msg.payload.decode()}` from `{msg.topic}` topic")
+        logger.debug(f"Received `{msg.payload.decode()}` from `{msg.topic}` topic")
         db_save_input(db_conn, msg.payload.decode())
 
     client.subscribe(MQTT_TOPIC)