Skip to content

Commit

Permalink
WEBHOOK conversion + cleanup work🎣
Browse files Browse the repository at this point in the history
  • Loading branch information
jokob-sk committed Oct 21, 2023
1 parent fdd1999 commit 55e398d
Show file tree
Hide file tree
Showing 17 changed files with 652 additions and 127 deletions.
22 changes: 0 additions & 22 deletions front/php/templates/language/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -513,30 +513,8 @@
"REPORT_MAIL_name" : "Enable email",
"REPORT_MAIL_description" : "If enabled an email is sent out with a list of changes you nove subscribed to. Please also fill out all remaining settings related to the SMTP setup below. If facing issues, set <code>LOG_LEVEL</code> to <code>debug</code> and check the <a href=\"/maintenance.php#tab_Logging\">error log</a>.",
"SYSTEM_TITLE" : "System Information",

"REPORT_TO_name" : "deprecated",
"REPORT_TO_description" : "deprecated",
"REPORT_FROM_name" : "deprecated",
"REPORT_FROM_description" : "deprecated",

"Webhooks_display_name" : "Webhooks",
"Webhooks_icon" : "<i class=\"fa fa-circle-nodes\"></i>",
"REPORT_WEBHOOK_name" : "Enable Webhooks",
"REPORT_WEBHOOK_description" : "Enable webhooks for notifications. Webhooks help you to connect to a lot of 3rd party tools, such as IFTTT, Zapier or <a href=\"https://n8n.io/\" target=\"_blank\">n8n</a> to name a few. Check out this simple <a href=\"https://github.com/jokob-sk/Pi.Alert/blob/main/docs/WEBHOOK_N8N.md\" target=\"_blank\">n8n guide here</a> to get started. If enabled, configure related settings below.",
"WEBHOOK_URL_name" : "Target URL",
"WEBHOOK_URL_description" : "Target URL starting with <code>http://</code> or <code>https://</code>.",
"WEBHOOK_PAYLOAD_name" : "Payload type",
"WEBHOOK_PAYLOAD_description" : "The Webhook payload data format for the <code>body</code> > <code>attachments</code> > <code>text</code> attribute in the payload json. See an example of the payload <a target=\"_blank\" href=\"https://github.com/jokob-sk/Pi.Alert/blob/main/back/webhook_json_sample.json\">here</a>. (e.g.: for discord use <code>text</code>)",
"WEBHOOK_REQUEST_METHOD_name" : "Request method",
"WEBHOOK_REQUEST_METHOD_description" : "The HTTP request method to be used for the webhook call.",
"WEBHOOK_SIZE_name" : "Max payload size",
"WEBHOOK_SIZE_description" : "The maximum size of the webhook payload as number of characters in the passed string. If above limit, it will be truncated and a <code>(text was truncated)</code> message is appended.",
"WEBHOOK_SECRET_name": "HMAC Secret",
"WEBHOOK_SECRET_description": "When set, use this secret to generate the SHA256-HMAC hex digest value of the request body, which will be passed as the <code>X-Webhook-Signature</code> header to the request. You can find more informations <a target=\"_blank\" href=\"https://github.com/jokob-sk/Pi.Alert/blob/main/docs/WEBHOOK_SECRET.md\">here</a>.",

"REPORT_TITLE" : "Report",
"REPORT_ERROR" : "The page you are looking for is temporarily unavailable, please try again after a few seconds",

"API_display_name" : "API",
"API_icon" : "<i class=\"fa fa-arrow-down-up-across-line\"></i>",
"API_CUSTOM_SQL_name" : "Custom endpoint",
Expand Down
49 changes: 28 additions & 21 deletions front/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,33 @@

### 🔌 Plugins & 📚 Docs

| Required | CurrentScan | Unique Prefix | Plugin Type | Link + Docs |
|-------------|-------------|-----------------------|------------------------|-----------------------------------------------------------|
| | Yes | ARPSCAN | Script | 📚[arp_scan](/front/plugins/arp_scan/) |
| | | CSVBCKP | Script | 📚[csv_backup](/front/plugins/csv_backup/) |
| Yes* | | DBCLNP | Script | 📚[db_cleanup](/front/plugins/db_cleanup/) |
| | | DDNS | Script | 📚[ddns_update](/front/plugins/ddns_update/) |
| | Yes | DHCPLSS | Script | 📚[dhcp_leases](/front/plugins/dhcp_leases/) |
| | | DHCPSRVS | Script | 📚[dhcp_servers](/front/plugins/dhcp_servers/) |
| | Yes | INTRNT | Script | 📚[internet_ip](/front/plugins/internet_ip/) |
| | | INTRSPD | Script | 📚[internet_speedtest](/front/plugins/internet_speedtest/)|
| Yes | | NEWDEV | Template | 📚[newdev_template](/front/plugins/newdev_template/) |
| | | PHOLUS | Script | 📚[pholus_scan](/front/plugins/pholus_scan/) |
| | | NMAP | Script | 📚[nmap_scan](/front/plugins/nmap_scan/) |
| | Yes | PIHOLE | External SQLite DB | 📚[pihole_scan](/front/plugins/pihole_scan/) |
| | | SETPWD | Script | 📚[set_password](/front/plugins/set_password/) |
| | | SNMPDSC | Script | 📚[snmp_discovery](/front/plugins/snmp_discovery/) |
| | Yes** | UNDIS | Script | 📚[undiscoverables](/front/plugins/undiscoverables/) |
| | Yes | UNFIMP | Script | 📚[unifi_import](/front/plugins/unifi_import/) |
| | | VNDRPDT | Script | 📚[vendor_update](/front/plugins/vendor_update/) |
| | | WEBMON | Script | 📚[website_monitor](/front/plugins/website_monitor/) |
| N/A | | N/A | SQL query | N/A, but the External SQLite DB plugins work similar |
| Required | CurrentScan | Unique Prefix | Data source | Type | Link + Docs |
|----------|-------------|---------------|--------------------|--------------|------------------------------------------------------------------|
| | | APPRISE | Script | 💬 publisher | 📚[_publisher_apprise](/front/plugins/_publisher_apprise/) |
| | Yes | ARPSCAN | Script | 🔍scanner | 📚[arp_scan](/front/plugins/arp_scan/) |
| | | CSVBCKP | Script | ⚙ system | 📚[csv_backup](/front/plugins/csv_backup/) |
| Yes* | | DBCLNP | Script | ⚙ system | 📚[db_cleanup](/front/plugins/db_cleanup/) |
| | | DDNS | Script | ⚙ system | 📚[ddns_update](/front/plugins/ddns_update/) |
| | Yes | DHCPLSS | Script | 🔍scanner | 📚[dhcp_leases](/front/plugins/dhcp_leases/) |
| | | DHCPSRVS | Script | 🔍scanner | 📚[dhcp_servers](/front/plugins/dhcp_servers/) |
| | Yes | INTRNT | Script | 🔍scanner | 📚[internet_ip](/front/plugins/internet_ip/) |
| | | INTRSPD | Script | 🔍scanner | 📚[internet_speedtest](/front/plugins/internet_speedtest/) |
| Yes | | NEWDEV | Template | ⚙ system | 📚[newdev_template](/front/plugins/newdev_template/) |
| | | PHOLUS | Script | 🔍scanner | 📚[pholus_scan](/front/plugins/pholus_scan/) |
| | | MQTT | Script | 💬 publisher | 📚[_publisher_mqtt](/front/plugins/_publisher_mqtt/) |
| | | NMAP | Script | 🔍scanner | 📚[nmap_scan](/front/plugins/nmap_scan/) |
| | | NTFY | Script | 💬 publisher | 📚[_publisher_ntfy](/front/plugins/_publisher_ntfy/) |
| | Yes | PIHOLE | External SQLite DB | 🔍scanner | 📚[pihole_scan](/front/plugins/pihole_scan/) |
| | | PUSHSAFER | Script | 💬 publisher | 📚[_publisher_pushsafer](/front/plugins/_publisher_pushsafer/) |
| | | SETPWD | Script | ⚙ system | 📚[set_password](/front/plugins/set_password/) |
| | | SMTP | Script | 💬 publisher | 📚[_publisher_email](/front/plugins/_publisher_email/) |
| | | SNMPDSC | Script | 🔍scanner | 📚[snmp_discovery](/front/plugins/snmp_discovery/) |
| | Yes** | UNDIS | Script | 🔍scanner | 📚[undiscoverables](/front/plugins/undiscoverables/) |
| | Yes | UNFIMP | Script | 🔍scanner | 📚[unifi_import](/front/plugins/unifi_import/) |
| | | VNDRPDT | Script | ⚙ system | 📚[vendor_update](/front/plugins/vendor_update/) |
| | | WEBHOOK | Script | 💬 publisher | 📚[_publisher_webhook](/front/plugins/_publisher_webhook/) |
| | | WEBMON | Script | 🔍scanner | 📚[website_monitor](/front/plugins/website_monitor/) |
| N/A | | N/A | SQL query | | N/A, but the External SQLite DB plugins work similar |


> \* The database cleanup plugin (`DBCLNP`) is not _required_ but the app will become unusable after a while if not executed.
Expand Down Expand Up @@ -135,6 +141,7 @@ Currently, these data sources are supported (valid `data_source` value).
| Pialert DB query | `pialert-db-query` | yes | Executes a SQL query on the PiAlert database in the `CMD` setting. |
| Template | `template` | no | Used to generate internal settings, such as default values. |
| External SQLite DB query | `sqlite-db-query` | yes | Executes a SQL query from the `CMD` setting on an external SQLite database mapped in the `DB_PATH` setting. |
| Plugin type | `plugin_type` | no | Specifies the type of the plugin and in which section the Plugin settings are displayed (`<general>|<system>|<scanner>|<publisher>`). |


> 🔎Example
Expand Down
2 changes: 1 addition & 1 deletion front/plugins/_publisher_apprise/apprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def main():
# Retrieve new notifications
new_notifications = notifications.getNew()

# Process the new notifications
# Process the new notifications (see the Notifications DB table for structure or check the /api/table_notifications.json endpoint)
for notification in new_notifications:

# Send notification
Expand Down
2 changes: 1 addition & 1 deletion front/plugins/_publisher_email/email_smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def main():
# Retrieve new notifications
new_notifications = notifications.getNew()

# Process the new notifications
# Process the new notifications (see the Notifications DB table for structure or check the /api/table_notifications.json endpoint)
for notification in new_notifications:

# Send notification
Expand Down
2 changes: 1 addition & 1 deletion front/plugins/_publisher_ntfy/ntfy.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def main():
# Retrieve new notifications
new_notifications = notifications.getNew()

# Process the new notifications
# Process the new notifications (see the Notifications DB table for structure or check the /api/table_notifications.json endpoint)
for notification in new_notifications:

# Send notification
Expand Down
13 changes: 9 additions & 4 deletions front/plugins/_publisher_pushsafer/pushsafer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import conf
from plugin_helper import Plugin_Objects, handleEmpty
from logger import mylog, append_line_to_file
from helper import timeNowTZ, get_setting_value
from helper import timeNowTZ, get_setting_value, hide_string
from notification import Notification_obj
from database import DB

Expand Down Expand Up @@ -48,11 +48,11 @@ def main():
# Retrieve new notifications
new_notifications = notifications.getNew()

# Process the new notifications
# Process the new notifications (see the Notifications DB table for structure or check the /api/table_notifications.json endpoint)
for notification in new_notifications:

# Send notification
response_text, response_status_code = send(notification["HTML"], notification["Text"])
response_text, response_status_code = send(notification["Text"])

# Log result
plugin_objects.add_object(
Expand All @@ -76,6 +76,11 @@ def send(text):
response_text = ''
response_status_code = ''

token = get_setting_value('PUSHSAFER_TOKEN')

mylog('verbose', [f'[{pluginName}] PUSHSAFER_TOKEN: "{hide_string(token)}"'])


try:
url = 'https://www.pushsafer.com/api'
post_fields = {
Expand All @@ -88,7 +93,7 @@ def send(text):
"d" : 'a',
"u" : get_setting_value('REPORT_DASHBOARD_URL'),
"ut" : 'Open Pi.Alert',
"k" : get_setting_value('PUSHSAFER_TOKEN'),
"k" : token,
}
response = requests.post(url, data=post_fields)

Expand Down
8 changes: 8 additions & 0 deletions front/plugins/_publisher_webhook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Overview

A plugin to publish a notification via the Webhook gateway. Webhooks help you to connect to a lot of 3rd party tools, such as IFTTT, Zapier or <a href="https://n8n.io/" target="_blank">n8n</a> to name a few. Check out this simple <a href="https://github.com/jokob-sk/Pi.Alert/blob/main/docs/WEBHOOK_N8N.md" target="_blank">n8n guide here</a> to get started. If enabled, configure related settings below.

### Usage

- Go to settings and fill in relevant details.

Loading

0 comments on commit 55e398d

Please sign in to comment.