Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
695f815
commit 651a54e
Showing
5 changed files
with
132 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
management/commands/pr_status_check_consistent_hardware.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import datetime | ||
import json | ||
|
||
from django.core.management.base import BaseCommand | ||
from django.utils import timezone | ||
|
||
from purple_robot_app.models import PurpleRobotDevice, PurpleRobotReading, my_slugify | ||
from purple_robot_app.management.commands.pr_check_status import log_alert, cancel_alert | ||
|
||
HARDWARE_PROBE = 'edu.northwestern.cbits.purple_robot_manager.probes.builtin.HardwareInformationProbe' | ||
|
||
TAG = 'device_hardware_changed' | ||
|
||
class Command(BaseCommand): | ||
def handle(self, *args, **options): | ||
for device in PurpleRobotDevice.objects.filter(mute_alerts=False): | ||
start = timezone.now() - datetime.timedelta(days=3) | ||
|
||
mac = None | ||
same_mac = True | ||
|
||
for reading in PurpleRobotReading.objects.filter(user_id=device.hash_key, probe=HARDWARE_PROBE, logged__gte=start): | ||
payload = json.loads(reading.payload) | ||
|
||
if mac == None: | ||
mac = payload['WIFI_MAC'] | ||
elif mac != payload['WIFI_MAC']: | ||
same_mac = False | ||
|
||
if same_mac: | ||
cancel_alert(tags=TAG, user_id=device.hash_key) | ||
else: | ||
log_alert(message='Device hardware changed.', severity=2, tags=TAG, user_id=device.hash_key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import datetime | ||
import json | ||
import requests | ||
|
||
from BeautifulSoup import BeautifulSoup | ||
|
||
from django.core.management.base import BaseCommand | ||
from django.utils import timezone | ||
|
||
from purple_robot_app.models import PurpleRobotDevice, PurpleRobotReading, my_slugify | ||
from purple_robot_app.management.commands.pr_check_status import log_alert, cancel_alert | ||
|
||
TAG = 'running_latest_version' | ||
|
||
class Command(BaseCommand): | ||
def handle(self, *args, **options): | ||
play_url = 'https://play.google.com/store/apps/details?id=edu.northwestern.cbits.purple_robot_manager' | ||
|
||
r = requests.get(play_url) | ||
|
||
soup = BeautifulSoup(r.text) | ||
|
||
if soup != None: | ||
changelog = '' | ||
|
||
changes = soup.findAll('div', { 'class': 'recent-change' }) | ||
|
||
for change in changes: | ||
if len(changelog) > 0: | ||
changelog += '\n' | ||
|
||
changelog += change.contents[0].strip() | ||
|
||
version_html = soup.find('div', { 'class': 'content', 'itemprop': 'softwareVersion' }) | ||
|
||
version = version_html.contents[0].strip() | ||
|
||
version_code = None | ||
version_code_html = soup.findAll('button', { 'class': 'dropdown-child' }) | ||
|
||
for div in version_code_html: | ||
if div.contents[0].strip() == 'Latest Version': | ||
version_code = float(div['data-dropdown-value']) | ||
|
||
for device in PurpleRobotDevice.objects.filter(mute_alerts=False): | ||
device_version = device.config_last_user_agent | ||
|
||
if device_version == None: | ||
log_alert(message='Unable to determine installed version.', severity=1, tags=TAG, user_id=device.hash_key) | ||
elif device_version.endswith(str(version)): | ||
cancel_alert(tags=TAG, user_id=device.hash_key) | ||
else: | ||
log_alert(message='Running an older version on Purple Robot: ' + device_version + '.', severity=1, tags=TAG, user_id=device.hash_key) | ||
else: | ||
print('Unable to fetch Play Store metadata.') | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters