PiHole work #513
This commit is contained in:
@@ -11,10 +11,10 @@ services:
|
|||||||
network_mode: host
|
network_mode: host
|
||||||
# restart: unless-stopped
|
# restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
# - ${APP_DATA_LOCATION}/pialert_dev/config:/home/pi/pialert/config
|
- ${APP_DATA_LOCATION}/pialert_dev/config:/home/pi/pialert/config
|
||||||
- ${APP_DATA_LOCATION}/pialert/config:/home/pi/pialert/config
|
# - ${APP_DATA_LOCATION}/pialert/config:/home/pi/pialert/config
|
||||||
# - ${APP_DATA_LOCATION}/pialert_dev/db:/home/pi/pialert/db
|
- ${APP_DATA_LOCATION}/pialert_dev/db:/home/pi/pialert/db
|
||||||
- ${APP_DATA_LOCATION}/pialert/db:/home/pi/pialert/db
|
# - ${APP_DATA_LOCATION}/pialert/db:/home/pi/pialert/db
|
||||||
# (optional) useful for debugging if you have issues setting up the container
|
# (optional) useful for debugging if you have issues setting up the container
|
||||||
- ${LOGS_LOCATION}:/home/pi/pialert/front/log
|
- ${LOGS_LOCATION}:/home/pi/pialert/front/log
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -349,6 +349,7 @@ function sanitize(data)
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
function numberArrayFromString(data)
|
function numberArrayFromString(data)
|
||||||
{
|
{
|
||||||
|
console.log(data)
|
||||||
data = JSON.parse(sanitize(data));
|
data = JSON.parse(sanitize(data));
|
||||||
return data.replace(/\[|\]/g, '').split(',').map(Number);
|
return data.replace(/\[|\]/g, '').split(',').map(Number);
|
||||||
}
|
}
|
||||||
@@ -516,6 +517,9 @@ function getNameByMacAddress(macAddress) {
|
|||||||
// A function used to make the IP address orderable
|
// A function used to make the IP address orderable
|
||||||
function formatIPlong(ipAddress) {
|
function formatIPlong(ipAddress) {
|
||||||
const parts = ipAddress.split('.');
|
const parts = ipAddress.split('.');
|
||||||
|
|
||||||
|
console.log(ipAddress)
|
||||||
|
|
||||||
if (parts.length !== 4) {
|
if (parts.length !== 4) {
|
||||||
throw new Error('Invalid IP address format');
|
throw new Error('Invalid IP address format');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ sys.path.append('/home/pi/pialert/pialert')
|
|||||||
from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64
|
from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64
|
||||||
from logger import mylog, append_line_to_file
|
from logger import mylog, append_line_to_file
|
||||||
from helper import timeNowTZ
|
from helper import timeNowTZ
|
||||||
from const import logPath, pialertPath
|
from const import logPath, pialertPath, fullDbPath
|
||||||
|
|
||||||
|
|
||||||
CUR_PATH = str(pathlib.Path(__file__).parent.resolve())
|
CUR_PATH = str(pathlib.Path(__file__).parent.resolve())
|
||||||
@@ -43,7 +43,7 @@ def main():
|
|||||||
mylog('verbose', ['[CSVBCKP] In script'])
|
mylog('verbose', ['[CSVBCKP] In script'])
|
||||||
|
|
||||||
# Connect to the PiAlert SQLite database
|
# Connect to the PiAlert SQLite database
|
||||||
conn = sqlite3.connect('/home/pi/pialert/db/pialert.db')
|
conn = sqlite3.connect(fullDbPath)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
# Execute your SQL query
|
# Execute your SQL query
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ sys.path.append('/home/pi/pialert/pialert')
|
|||||||
from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64
|
from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64
|
||||||
from logger import mylog, append_line_to_file
|
from logger import mylog, append_line_to_file
|
||||||
from helper import timeNowTZ, get_setting_value
|
from helper import timeNowTZ, get_setting_value
|
||||||
from const import logPath, pialertPath
|
from const import logPath, pialertPath, fullDbPath
|
||||||
|
|
||||||
|
|
||||||
CUR_PATH = str(pathlib.Path(__file__).parent.resolve())
|
CUR_PATH = str(pathlib.Path(__file__).parent.resolve())
|
||||||
@@ -44,7 +44,7 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
# Execute cleanup/upkeep
|
# Execute cleanup/upkeep
|
||||||
cleanup_database('/home/pi/pialert/db/pialert.db', DAYS_TO_KEEP_EVENTS, PHOLUS_DAYS_DATA, HRS_TO_KEEP_NEWDEV, PLUGINS_KEEP_HIST)
|
cleanup_database(fullDbPath, DAYS_TO_KEEP_EVENTS, PHOLUS_DAYS_DATA, HRS_TO_KEEP_NEWDEV, PLUGINS_KEEP_HIST)
|
||||||
|
|
||||||
mylog('verbose', ['[DBCLNP] Cleanup complete file '])
|
mylog('verbose', ['[DBCLNP] Cleanup complete file '])
|
||||||
|
|
||||||
|
|||||||
@@ -16,21 +16,21 @@ sys.path.append('/home/pi/pialert/pialert')
|
|||||||
from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64
|
from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64
|
||||||
from logger import mylog, append_line_to_file
|
from logger import mylog, append_line_to_file
|
||||||
from helper import timeNowTZ, get_setting_value
|
from helper import timeNowTZ, get_setting_value
|
||||||
from const import logPath, pialertPath
|
from const import logPath, pialertPath, fullDbPath
|
||||||
|
|
||||||
|
|
||||||
CUR_PATH = str(pathlib.Path(__file__).parent.resolve())
|
CUR_PATH = str(pathlib.Path(__file__).parent.resolve())
|
||||||
LOG_FILE = os.path.join(CUR_PATH, 'script.log')
|
LOG_FILE = os.path.join(CUR_PATH, 'script.log')
|
||||||
RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log')
|
RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log')
|
||||||
|
|
||||||
pluginName= 'NTFPRCS'
|
pluginName = 'NTFPRCS'
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
mylog('verbose', [f'[{pluginName}] In script'])
|
mylog('verbose', [f'[{pluginName}] In script'])
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
# process_notifications('/home/pi/pialert/db/pialert.db')
|
# process_notifications(fullDbPath)
|
||||||
|
|
||||||
mylog('verbose', [f'[{pluginName}] Script finished'])
|
mylog('verbose', [f'[{pluginName}] Script finished'])
|
||||||
|
|
||||||
@@ -40,9 +40,7 @@ def main():
|
|||||||
# Cleanup / upkeep database
|
# Cleanup / upkeep database
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
def process_notifications (dbPath):
|
def process_notifications (dbPath):
|
||||||
"""
|
|
||||||
Cleaning out old records from the tables that don't need to keep all data.
|
|
||||||
"""
|
|
||||||
# Connect to the PiAlert SQLite database
|
# Connect to the PiAlert SQLite database
|
||||||
conn = sqlite3.connect(dbPath)
|
conn = sqlite3.connect(dbPath)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|||||||
@@ -83,7 +83,7 @@
|
|||||||
{
|
{
|
||||||
"function": "CMD",
|
"function": "CMD",
|
||||||
"type": "text",
|
"type": "text",
|
||||||
"default_value":"SELECT n.hwaddr AS Object_PrimaryID, {s-quote}null{s-quote} AS Object_SecondaryID, datetime() AS DateTime, na.ip AS Watched_Value1, n.lastQuery AS Watched_Value2, na.name AS Watched_Value3, n.macVendor AS Watched_Value4, {s-quote}null{s-quote} AS Extra, n.hwaddr AS ForeignKey FROM EXTERNAL_PIHOLE.Network AS n LEFT JOIN EXTERNAL_PIHOLE.Network_Addresses AS na ON na.network_id = n.id WHERE n.hwaddr NOT LIKE {s-quote}ip-%{s-quote} AND n.hwaddr <> {s-quote}00:00:00:00:00:00{s-quote} AND na.ip <> null;",
|
"default_value":"SELECT n.hwaddr AS Object_PrimaryID, {s-quote}null{s-quote} AS Object_SecondaryID, datetime() AS DateTime, na.ip AS Watched_Value1, n.lastQuery AS Watched_Value2, na.name AS Watched_Value3, n.macVendor AS Watched_Value4, {s-quote}null{s-quote} AS Extra, n.hwaddr AS ForeignKey FROM EXTERNAL_PIHOLE.Network AS n LEFT JOIN EXTERNAL_PIHOLE.Network_Addresses AS na ON na.network_id = n.id WHERE n.hwaddr NOT LIKE {s-quote}ip-%{s-quote} AND n.hwaddr is not {s-quote}00:00:00:00:00:00{s-quote} AND na.ip is not null",
|
||||||
"options": [],
|
"options": [],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name" : [{
|
"name" : [{
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ sys.path.append('/home/pi/pialert/pialert')
|
|||||||
from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64, handleEmpty
|
from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64, handleEmpty
|
||||||
from logger import mylog, append_line_to_file
|
from logger import mylog, append_line_to_file
|
||||||
from helper import timeNowTZ
|
from helper import timeNowTZ
|
||||||
from const import logPath, pialertPath
|
from const import logPath, pialertPath, fullDbPath
|
||||||
from device import query_MAC_vendor
|
from device import query_MAC_vendor
|
||||||
|
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ def main():
|
|||||||
# Resolve missing vendors
|
# Resolve missing vendors
|
||||||
plugin_objects = Plugin_Objects(RESULT_FILE)
|
plugin_objects = Plugin_Objects(RESULT_FILE)
|
||||||
|
|
||||||
plugin_objects = update_vendors('/home/pi/pialert/db/pialert.db', plugin_objects)
|
plugin_objects = update_vendors(fullDbPath, plugin_objects)
|
||||||
|
|
||||||
plugin_objects.write_result_file()
|
plugin_objects.write_result_file()
|
||||||
|
|
||||||
|
|||||||
@@ -327,6 +327,8 @@ def execute_plugin(db, plugin, pluginsState = plugins_state() ):
|
|||||||
try:
|
try:
|
||||||
sql.execute ("ATTACH DATABASE '"+ fullSqlitePath +"' AS EXTERNAL_"+plugin["unique_prefix"])
|
sql.execute ("ATTACH DATABASE '"+ fullSqlitePath +"' AS EXTERNAL_"+plugin["unique_prefix"])
|
||||||
arr = db.get_sql_array (q)
|
arr = db.get_sql_array (q)
|
||||||
|
sql.execute ("DETACH DATABASE EXTERNAL_"+plugin["unique_prefix"])
|
||||||
|
|
||||||
except sqlite3.Error as e:
|
except sqlite3.Error as e:
|
||||||
mylog('none',[f'[Plugins] ⚠ ERROR: DB_PATH setting ({fullSqlitePath}) for plugin {plugin["unique_prefix"]}. Did you mount it correctly?'])
|
mylog('none',[f'[Plugins] ⚠ ERROR: DB_PATH setting ({fullSqlitePath}) for plugin {plugin["unique_prefix"]}. Did you mount it correctly?'])
|
||||||
mylog('none',[f'[Plugins] ⚠ ERROR: ATTACH DATABASE failed with SQL ERROR: ', e])
|
mylog('none',[f'[Plugins] ⚠ ERROR: ATTACH DATABASE failed with SQL ERROR: ', e])
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ def get_notifications (db):
|
|||||||
|
|
||||||
mylog('verbose', ['[Notification] included sections: ', conf.INCLUDED_SECTIONS ])
|
mylog('verbose', ['[Notification] included sections: ', conf.INCLUDED_SECTIONS ])
|
||||||
|
|
||||||
if 'new_devices' in conf.INCLUDED_SECTIONS :
|
if 'new_devices' in conf.INCLUDED_SECTIONS:
|
||||||
# Compose New Devices Section
|
# Compose New Devices Section
|
||||||
sqlQuery = """SELECT eve_MAC as MAC, eve_DateTime as Datetime, dev_LastIP as IP, eve_EventType as "Event Type", dev_Name as "Device name", dev_Comments as Comments FROM Events_Devices
|
sqlQuery = """SELECT eve_MAC as MAC, eve_DateTime as Datetime, dev_LastIP as IP, eve_EventType as "Event Type", dev_Name as "Device name", dev_Comments as Comments FROM Events_Devices
|
||||||
WHERE eve_PendingAlertEmail = 1
|
WHERE eve_PendingAlertEmail = 1
|
||||||
@@ -75,8 +75,9 @@ def get_notifications (db):
|
|||||||
}
|
}
|
||||||
json_new_devices = json_obj.json["data"]
|
json_new_devices = json_obj.json["data"]
|
||||||
|
|
||||||
if 'down_devices' in conf.INCLUDED_SECTIONS :
|
if 'down_devices' in conf.INCLUDED_SECTIONS:
|
||||||
# Compose Devices Down Section
|
# Compose Devices Down Section
|
||||||
|
# - select only Down Alerts with pending email of devices that didn't reconnect within the specified time window
|
||||||
sqlQuery = f"""
|
sqlQuery = f"""
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM Events AS down_events
|
FROM Events AS down_events
|
||||||
@@ -102,7 +103,7 @@ def get_notifications (db):
|
|||||||
}
|
}
|
||||||
json_down_devices = json_obj.json["data"]
|
json_down_devices = json_obj.json["data"]
|
||||||
|
|
||||||
if 'events' in conf.INCLUDED_SECTIONS :
|
if 'events' in conf.INCLUDED_SECTIONS:
|
||||||
# Compose Events Section
|
# Compose Events Section
|
||||||
sqlQuery = """SELECT eve_MAC as MAC, eve_DateTime as Datetime, dev_LastIP as IP, eve_EventType as "Event Type", dev_Name as "Device name", dev_Comments as Comments FROM Events_Devices
|
sqlQuery = """SELECT eve_MAC as MAC, eve_DateTime as Datetime, dev_LastIP as IP, eve_EventType as "Event Type", dev_Name as "Device name", dev_Comments as Comments FROM Events_Devices
|
||||||
WHERE eve_PendingAlertEmail = 1
|
WHERE eve_PendingAlertEmail = 1
|
||||||
@@ -142,7 +143,7 @@ def get_notifications (db):
|
|||||||
"events_meta": json_events_meta,
|
"events_meta": json_events_meta,
|
||||||
"plugins": json_plugins,
|
"plugins": json_plugins,
|
||||||
"plugins_meta": json_plugins_meta,
|
"plugins_meta": json_plugins_meta,
|
||||||
}
|
}
|
||||||
|
|
||||||
return final_json
|
return final_json
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user