internet_ip plugin 0.3

This commit is contained in:
Jokob-sk
2023-09-20 22:20:41 +10:00
parent c08b70a38d
commit c5d1cd919a
14 changed files with 55 additions and 22 deletions

View File

@@ -62,7 +62,8 @@
"settings": [ "settings": [
{ {
"function": "RUN", "function": "RUN",
"events": ["run"],
"type": "text.select", "type": "text.select",
"default_value":"schedule", "default_value":"schedule",
"options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"], "options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],

View File

@@ -48,7 +48,8 @@
"settings": [ "settings": [
{ {
"function": "RUN", "function": "RUN",
"events": ["run"],
"type": "text.select", "type": "text.select",
"default_value":"schedule", "default_value":"schedule",
"options": ["disabled", "once", "schedule", "always_after_scan"], "options": ["disabled", "once", "schedule", "always_after_scan"],

View File

@@ -309,7 +309,8 @@
], ],
"settings":[ "settings":[
{ {
"function": "RUN", "function": "RUN",
"events": ["run"],
"type": "text.select", "type": "text.select",
"default_value":"disabled", "default_value":"disabled",
"options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"], "options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],

View File

@@ -273,7 +273,8 @@
], ],
"settings":[ "settings":[
{ {
"function": "RUN", "function": "RUN",
"events": ["run"],
"type": "text.select", "type": "text.select",
"default_value":"disabled", "default_value":"disabled",
"options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"], "options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],

View File

@@ -78,6 +78,7 @@
"settings": [ "settings": [
{ {
"function": "RUN", "function": "RUN",
"events": ["run"],
"type": "text.select", "type": "text.select",
"default_value": "schedule", "default_value": "schedule",
"options": [ "options": [
@@ -254,14 +255,33 @@
"description": [ "description": [
{ {
"language_code": "en_us", "language_code": "en_us",
"string": "Send a notification if selected values change. Use <code>CTRL + Click</code> to select/deselect. <ul> <li><code>Watched_Value1</code> is response status code (e.g.: 200, 404)</li><li><code>Watched_Value2</code> is Latency (not recommended)</li><li><code>Watched_Value3</code> unused </li><li><code>Watched_Value4</code> unused </li></ul>" "string": "Send a notification if selected values change. Use <code>CTRL + Click</code> to select/deselect. <ul> <li><code>Watched_Value1</code> is Internet IP/li><li><code>Watched_Value2</code> is Previous IP (not recommended)</li><li><code>Watched_Value3</code> unused </li><li><code>Watched_Value4</code> unused </li></ul>"
},
{
"language_code": "es_es",
"string": "Envíe una notificación si los valores seleccionados cambian. Use <code>CTRL + Click</code> para seleccionar/deseleccionar. <ul> <li><code>Watched_Value1</code> es un código de estado de respuesta (por ejemplo: 200, 404) </li><li><code>Valor_observado2</code> es Latencia (no recomendado)</li><li><code>Valor_observado3</code> no utilizado </li><li><code>Valor_observado4 </ code> sin usar </li></ul>"
} }
] ]
} },
{
"function": "REPORT_ON",
"type": "text.multiselect",
"default_value":["new","watched-changed"],
"options": ["new","watched-changed","watched-not-changed", "missing-in-last-scan"],
"localized": ["name", "description"],
"name" :[{
"language_code":"en_us",
"string" : "Report on"
},
{
"language_code":"es_es",
"string" : "Informar sobre"
} ] ,
"description":[{
"language_code":"en_us",
"string" : "Send a notification only on these statuses. <code>new</code> means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. <code>watched-changed</code> means that selected <code>Watched_ValueN</code> columns changed."
},
{
"language_code":"es_es",
"string" : "Envíe una notificación solo en estos estados. <code>new</code> significa que se descubrió un nuevo objeto único (una combinación única de PrimaryId y SecondaryId). <code>watched-changed</code> significa que las columnas <code>Watched_ValueN</code> seleccionadas cambiaron."
}]
}
], ],
"database_column_definitions": [ "database_column_definitions": [
{ {

View File

@@ -10,6 +10,7 @@ import hashlib
import csv import csv
import subprocess import subprocess
import re import re
import base64
import sqlite3 import sqlite3
from io import StringIO from io import StringIO
from datetime import datetime from datetime import datetime
@@ -41,7 +42,7 @@ def main():
parser.add_argument('DDNS_DOMAIN', action="store", help="Dynamic DNS (DDNS) domain name") parser.add_argument('DDNS_DOMAIN', action="store", help="Dynamic DNS (DDNS) domain name")
parser.add_argument('DIG_GET_IP_ARG', action="store", help="Arguments for the 'dig' command to retrieve the IP address") parser.add_argument('DIG_GET_IP_ARG', action="store", help="Arguments for the 'dig' command to retrieve the IP address")
args = parser.parse_args() values = parser.parse_args()
PREV_IP = values.prev_ip.split('=')[1] PREV_IP = values.prev_ip.split('=')[1]
DDNS_ACTIVE = values.DDNS_ACTIVE.split('=')[1] DDNS_ACTIVE = values.DDNS_ACTIVE.split('=')[1]
@@ -54,9 +55,9 @@ def main():
mylog('verbose', ['[INTRNT] DIG_GET_IP_ARG: ', DIG_GET_IP_ARG]) mylog('verbose', ['[INTRNT] DIG_GET_IP_ARG: ', DIG_GET_IP_ARG])
# Decode the base64-encoded value to get the actual value in ASCII format. # Decode the base64-encoded value to get the actual value in ASCII format.
DIG_GET_IP_ARG = base64.b64decode(DIG_GET_IP_ARG).decode('ascii') DIG_GET_IP_ARG = base64.b64decode(DIG_GET_IP_ARG.split('b')[1]).decode('ascii')
mylog('verbose', ['[INTRNT] DIG_GET_IP_ARG resolved: ', DIG_GET_IP_ARG]) mylog('verbose', [f'[INTRNT] DIG_GET_IP_ARG resolved: {DIG_GET_IP_ARG} '])
# if internet_IP != "" : # if internet_IP != "" :
# sql.execute (f"""INSERT INTO CurrentScan (cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod) # sql.execute (f"""INSERT INTO CurrentScan (cur_MAC, cur_IP, cur_Vendor, cur_ScanMethod)
@@ -90,10 +91,10 @@ def main():
primaryId = 'Internet', # MAC (Device Name) primaryId = 'Internet', # MAC (Device Name)
secondaryId = '', secondaryId = '',
watched1 = new_internet_IP, # IP Address watched1 = new_internet_IP, # IP Address
watched2 = f'Previous IP: {prev_ip}', watched2 = f'Previous IP: {PREV_IP}',
watched3 = '', watched3 = '',
watched4 = '', watched4 = '',
extra = f'Previous IP: {prev_ip}', extra = f'Previous IP: {PREV_IP}',
foreignKey = 'Internet') foreignKey = 'Internet')
plugin_objects.write_result_file() plugin_objects.write_result_file()
@@ -120,18 +121,18 @@ def check_internet_IP ( DDNS_ACTIVE, DDNS_UPDATE_URL, DDNS_USER, DDNS_PASSWORD,
# Get previous stored IP # Get previous stored IP
previous_IP = '0.0.0.0' previous_IP = '0.0.0.0'
if PREV_IP is not None and len(result) > 0 : if PREV_IP is not None and len(PREV_IP) > 0 :
previous_IP = PREV_IP previous_IP = PREV_IP
mylog('verbose', ['[INTRNT] ', previous_IP]) mylog('verbose', ['[INTRNT] ', previous_IP])
# logging # logging
append_line_to_file (logPath + '/IP_changes.log', '['+str(timeNowTZ()) +']\t'+ pNewIP +'\n') append_line_to_file (logPath + '/IP_changes.log', '['+str(timeNowTZ()) +']\t'+ internet_IP +'\n')
# Get Dynamic DNS IP # Get Dynamic DNS IP
if DDNS_ACTIVE : if DDNS_ACTIVE :
mylog('verbose', ['[DDNS] Retrieving Dynamic DNS IP']) mylog('verbose', ['[DDNS] Retrieving Dynamic DNS IP'])
dns_IP = get_dynamic_DNS_IP() dns_IP = get_dynamic_DNS_IP(DDNS_DOMAIN)
# Check Dynamic DNS IP # Check Dynamic DNS IP
if dns_IP == "" or dns_IP == "0.0.0.0" : if dns_IP == "" or dns_IP == "0.0.0.0" :

View File

@@ -319,6 +319,7 @@
"settings":[ "settings":[
{ {
"function": "RUN", "function": "RUN",
"events": ["run"],
"type": "text.select", "type": "text.select",
"default_value":"disabled", "default_value":"disabled",
"options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"], "options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],

View File

@@ -56,7 +56,8 @@
"settings": [ "settings": [
{ {
"function": "RUN", "function": "RUN",
"events": ["run"],
"type": "text.select", "type": "text.select",
"default_value":"disabled", "default_value":"disabled",
"options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"], "options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],

View File

@@ -41,7 +41,8 @@
], ],
"settings":[ "settings":[
{ {
"function": "RUN", "function": "RUN",
"events": ["run"],
"type": "text.select", "type": "text.select",
"default_value":"disabled", "default_value":"disabled",
"options": ["disabled", "before_config_save"], "options": ["disabled", "before_config_save"],

View File

@@ -305,7 +305,8 @@
], ],
"settings":[ "settings":[
{ {
"function": "RUN", "function": "RUN",
"events": ["run"],
"type": "text.select", "type": "text.select",
"default_value":"disabled", "default_value":"disabled",
"options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"], "options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],

View File

@@ -47,6 +47,7 @@
"settings": [ "settings": [
{ {
"function": "RUN", "function": "RUN",
"events": ["run"],
"type": "text.select", "type": "text.select",
"default_value":"disabled", "default_value":"disabled",
"options": ["disabled", "once", "always_after_scan"], "options": ["disabled", "once", "always_after_scan"],

View File

@@ -488,6 +488,7 @@
} }
], ],
"function": "RUN", "function": "RUN",
"events": ["run"],
"localized": [ "localized": [
"name", "name",
"description" "description"

View File

@@ -31,6 +31,7 @@
"settings": [ "settings": [
{ {
"function": "RUN", "function": "RUN",
"events": ["run"],
"type": "text.select", "type": "text.select",
"default_value": "schedule", "default_value": "schedule",
"options": [ "options": [

View File

@@ -308,7 +308,8 @@
], ],
"settings":[ "settings":[
{ {
"function": "RUN", "function": "RUN",
"events": ["run"],
"type": "text.select", "type": "text.select",
"default_value":"disabled", "default_value":"disabled",
"options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"], "options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],