Skip to content

Commit

Permalink
Merge pull request #22 from dkmur/develop
Browse files Browse the repository at this point in the history
Add Webhooks to Monitor script
  • Loading branch information
bbdoc authored Dec 7, 2022
2 parents d63f14d + 5a1c927 commit c03ee0e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
4 changes: 2 additions & 2 deletions atlas.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/system/bin/sh
# version 1.5.3
# version 1.5.6

#Version checks
Ver55atlas="1.0"
VerMonitor="3.1.8"
VerMonitor="3.2.1"
VerATVsender="1.7.1"

#Create logfile
Expand Down
23 changes: 21 additions & 2 deletions atlas_monitor.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/system/bin/sh
# version 3.1.8
# version 3.2.1

# Monitor by Oldmole && bbdoc

Expand Down Expand Up @@ -39,16 +39,29 @@ 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 @- <<DATA
{
"WHType": "ATVMonitor",
"deviceName": "${origin}",
"issue": "${issue}",
"action": "${action}",
"script": "atlas_monitor.sh"
}
DATA
}


echo "`date +%Y-%m-%d_%T` [MONITORBOT] Starting atlas data monitor in 5 mins, loop is $monitor_interval seconds" >> $logfile
sleep 300
while :
Expand Down Expand Up @@ -96,6 +109,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 ]
Expand All @@ -107,17 +121,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))
Expand All @@ -136,6 +153,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))
Expand All @@ -146,6 +164,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
Expand Down
2 changes: 1 addition & 1 deletion wh_receiver/sql/tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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` (
Expand Down
7 changes: 4 additions & 3 deletions wh_receiver/start_whreceiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c03ee0e

Please sign in to comment.