From 42c87188f9f3398f13c2cadd8647a9b0ea4c5715 Mon Sep 17 00:00:00 2001 From: bbdoc Date: Wed, 7 Dec 2022 15:48:48 +0100 Subject: [PATCH 1/4] Add Monitor Webhooks --- atlas.sh | 4 ++-- atlas_monitor.sh | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/atlas.sh b/atlas.sh index 174c645..1b1a39a 100755 --- a/atlas.sh +++ b/atlas.sh @@ -1,9 +1,9 @@ #!/system/bin/sh -# version 1.5.3 +# version 1.5.4 #Version checks Ver55atlas="1.0" -VerMonitor="3.1.8" +VerMonitor="3.1.9" VerATVsender="1.7.1" #Create logfile diff --git a/atlas_monitor.sh b/atlas_monitor.sh index c73cf0f..1df94ee 100755 --- a/atlas_monitor.sh +++ b/atlas_monitor.sh @@ -1,5 +1,5 @@ #!/system/bin/sh -# version 3.1.8 +# version 3.1.9 # Monitor by Oldmole && bbdoc @@ -39,16 +39,27 @@ stop_start_atlas () { [[ $debug == "true" ]] && echo "`date +%Y-%m-%d_%T` [MONITORBOT] Running the start mapping service of Atlas" >> $logfile am startservice com.pokemod.atlas/com.pokemod.atlas.services.MappingService sleep 1 - } stop_pogo () { am force-stop com.nianticlabs.pokemongo & rm -rf /data/data/com.nianticlabs.pokemongo/cache/* sleep 5 [[ $debug == "true" ]] && echo "`date +%Y-%m-%d_%T` [MONITORBOT] Killing pogo and clearing junk" >> $logfile +} +send_webhook () { + $issue = $1; + $action = $2; + curl -k -X POST $atvdetails_receiver_host:$atvdetails_receiver_port/webhook -H "Accept: application/json" -H "Content-Type: application/json" --data-binary @- <> $logfile sleep 300 while : @@ -96,6 +107,7 @@ do then echo "`date +%Y-%m-%d_%T` [MONITORBOT] Device Lost Atlas License" >> $logfile [[ ! -z $discord_webhook ]] && curl -S -k -L --fail --show-error -F "payload_json={\"content\": \"__**$origin**__: UNLICENSED !!! Check Atlas Dashboard\"}" $discord_webhook &>/dev/null + send_webhook "Lost Licence" "No action" touch /sdcard/not_licensed elif [ -f /sdcard/not_licensed ] && [ $not_licensed -eq 0 ] @@ -107,17 +119,20 @@ do elif [ $emptycheck != 9 ] && [ $devicestatus != $deviceonline ] && [ $atlasdead == 2 ] then echo "`date +%Y-%m-%d_%T` [MONITORBOT] Atlas must be dead, rebooting device" >> $logfile + send_webhook "Atlas Dead" "Reboot" [[ ! -z $discord_webhook ]] && [[ $atlas_died != "false" ]] && curl -S -k -L --fail --show-error -F "payload_json={\"content\": \"__**$origin**__: atlas died, reboot\"}" $discord_webhook &>/dev/null reboot elif [ $emptycheck != 9 ] && [ $pogodead == 2 ] then echo "`date +%Y-%m-%d_%T` [MONITORBOT] Pogo must be dead, rebooting device" >> $logfile + send_webhook "Pogo Dead" "Reboot" [[ ! -z $discord_webhook ]] && [[ $pogo_died != "false" ]] && curl -S -k -L --fail --show-error -F "payload_json={\"content\": \"__**$origin**__: pogo died, reboot\"}" $discord_webhook &>/dev/null reboot elif [ $emptycheck != 9 ] && [ $devicestatus != $deviceonline ] && [ $atlasdead != 2 ] then echo "`date +%Y-%m-%d_%T` [MONITORBOT] Device must be offline. Running a stop mapping service of Atlas, killing pogo and clearing junk" >> $logfile + send_webhook "Device Offline" "Kill Pogo and Clear Junk" [[ ! -z $discord_webhook ]] && [[ $device_offline != "false" ]] && curl -S -k -L --fail --show-error -F "payload_json={\"content\": \"__**$origin**__: device offline, restarting atlas and pogo\"}" $discord_webhook &>/dev/null stop_start_atlas atlasdead=$((atlasdead+1)) @@ -136,6 +151,7 @@ do if [ "$focusedapp" != "com.nianticlabs.pokemongo" ] then echo "`date +%Y-%m-%d_%T` [MONITORBOT] Something is not right! Pogo is not in focus. Killing pogo and clearing junk" >> $logfile + send_webhook "Pogo not in Focus" "Kill Pogo and Clear Junk" [[ ! -z $discord_webhook ]] && [[ $pogo_not_focused != "false" ]] && curl -S -k -L --fail --show-error -F "payload_json={\"content\": \"__**$origin**__: pogo not in focus, Killing and clearing junk\"}" $discord_webhook &>/dev/null stop_pogo pogodead=$((pogodead+1)) @@ -146,6 +162,7 @@ do fi else echo "`date +%Y-%m-%d_%T` [MONITORBOT] Something happened! Some kind of error" >> $logfile + send_webhook "Unknown Error" "No action" [[ ! -z $discord_webhook ]] && curl -S -k -L --fail --show-error -F "payload_json={\"content\": \"__**$origin**__: no clue what happend, but its not good\"}" $discord_webhook &>/dev/null fi sleep $monitor_interval From 08488ec34397898062da0f60588dc668ce4707c3 Mon Sep 17 00:00:00 2001 From: bbdoc Date: Wed, 7 Dec 2022 16:10:47 +0100 Subject: [PATCH 2/4] Add WHType and script name to Webhook --- atlas.sh | 4 ++-- atlas_monitor.sh | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/atlas.sh b/atlas.sh index 1b1a39a..2642070 100755 --- a/atlas.sh +++ b/atlas.sh @@ -1,9 +1,9 @@ #!/system/bin/sh -# version 1.5.4 +# version 1.5.5 #Version checks Ver55atlas="1.0" -VerMonitor="3.1.9" +VerMonitor="3.2" VerATVsender="1.7.1" #Create logfile diff --git a/atlas_monitor.sh b/atlas_monitor.sh index 1df94ee..08b3ffe 100755 --- a/atlas_monitor.sh +++ b/atlas_monitor.sh @@ -1,5 +1,5 @@ #!/system/bin/sh -# version 3.1.9 +# version 3.2 # Monitor by Oldmole && bbdoc @@ -52,9 +52,11 @@ send_webhook () { $action = $2; curl -k -X POST $atvdetails_receiver_host:$atvdetails_receiver_port/webhook -H "Accept: application/json" -H "Content-Type: application/json" --data-binary @- < Date: Wed, 7 Dec 2022 16:26:17 +0100 Subject: [PATCH 3/4] Correct Variable Assignment --- atlas.sh | 4 ++-- atlas_monitor.sh | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/atlas.sh b/atlas.sh index 2642070..53669f5 100755 --- a/atlas.sh +++ b/atlas.sh @@ -1,9 +1,9 @@ #!/system/bin/sh -# version 1.5.5 +# version 1.5.6 #Version checks Ver55atlas="1.0" -VerMonitor="3.2" +VerMonitor="3.2.1" VerATVsender="1.7.1" #Create logfile diff --git a/atlas_monitor.sh b/atlas_monitor.sh index 08b3ffe..b2e1755 100755 --- a/atlas_monitor.sh +++ b/atlas_monitor.sh @@ -1,5 +1,5 @@ #!/system/bin/sh -# version 3.2 +# version 3.2.1 # Monitor by Oldmole && bbdoc @@ -48,8 +48,8 @@ stop_pogo () { } send_webhook () { - $issue = $1; - $action = $2; + issue=$1; + action=$2; curl -k -X POST $atvdetails_receiver_host:$atvdetails_receiver_port/webhook -H "Accept: application/json" -H "Content-Type: application/json" --data-binary @- < Date: Wed, 7 Dec 2022 16:40:10 +0100 Subject: [PATCH 4/4] Add script to ATVMonitor --- wh_receiver/sql/tables.sql | 2 +- wh_receiver/start_whreceiver.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/wh_receiver/sql/tables.sql b/wh_receiver/sql/tables.sql index 91254e6..bbbd1b8 100644 --- a/wh_receiver/sql/tables.sql +++ b/wh_receiver/sql/tables.sql @@ -78,7 +78,7 @@ CREATE TABLE IF NOT EXISTS `ATVMonitor` ( `deviceName` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL, `issue` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, `action` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - PRIMARY KEY (`deviceName`) + `script` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE IF NOT EXISTS `version` ( diff --git a/wh_receiver/start_whreceiver.py b/wh_receiver/start_whreceiver.py index 1326e82..0d7f519 100644 --- a/wh_receiver/start_whreceiver.py +++ b/wh_receiver/start_whreceiver.py @@ -91,13 +91,14 @@ def webhook(): deviceName = validate_string(request.json["deviceName"]) issue = validate_string(request.json["issue"]) action = validate_string(request.json["action"]) + script = validate_string(request.json["script"]) insert_stmt_monitor = ( - "INSERT INTO ATVMonitor (timestamp, deviceName, issue, action)" - "VALUES ( %s, %s, %s, %s )" + "INSERT INTO ATVMonitor (timestamp, deviceName, issue, action, script)" + "VALUES ( %s, %s, %s, %s, %s )" ) - data_monitor = ( str(timestamp), str(deviceName), str(issue), str(action) ) + data_monitor = ( str(timestamp), str(deviceName), str(issue), str(action), str(script) ) try: connection_object = connection_pool.get_connection()