Created
February 25, 2018 02:50
-
-
Save jtallieu/acdcc93042fabeb049048a59f2f0c360 to your computer and use it in GitHub Desktop.
Toggle Eagle Eye Networks analytics on an esn from a master account user using the API
This file contains hidden or 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 script till toggle the analytics feature on an esn in a tenant account. | |
To disable the analytics, you must delete the 'active_application' settings in | |
the user settings of the camera. In order to re-enable the feature, you must | |
add the settings back to the 'active_settings'. To accomplish this, we must | |
store the settings somewhere in the camera settings so that when we want to | |
enable we can copy the settings from somewhere. This script uses | |
'inactive_application' to hold the settings for us. You may choose another | |
name if you like. | |
""" | |
import json | |
import requests | |
from pprint import pprint | |
from requests.cookies import cookiejar_from_dict | |
# ====== SETUP ====== | |
# Define the camera to be managed | |
esn = "100c44ce" # Camera to manage | |
tenant_account = "00010606" # Tenant account the esn belongs to | |
host = "https://c001.eagleeyenetworks.com/g" # host base url | |
# For simplicitly, we'll assume you know how to get your sessions id | |
# either get your cookie from an authenticated session OR | |
# follow the auth API. | |
master_account_session_id = "c001~09...3e8" # Authed token | |
# === Setup Done ===== | |
session = requests.Session() | |
session.cookies = cookiejar_from_dict(dict(videobank_sessionid=master_account_session_id, auth_key=master_account_session_id)) | |
# Get into the tenant account | |
resp = session.post("{}/aaa/switch_account".format(host), data={'account_id': tenant_account}) | |
print "Switch Account {}: [{}]".format(tenant_account, resp.status_code) | |
resp.raise_for_status() | |
# Get device information | |
print "Collecting {} settings ....".format(esn) | |
resp = session.get("{}/device?id={}&include_aggregate=True&is_cloud_only=0".format(host, esn)) | |
resp.raise_for_status() | |
# Manage the VA Application | |
# Get the active application settings | |
app_settings = resp.json().get('camera_parameters', {}).get('user_settings', {}).get('settings', {}).get('active_application', {}) | |
old_app_settings = resp.json().get('camera_parameters', {}).get('user_settings', {}).get('settings', {}).get('inactive_application', {}) | |
if app_settings: | |
print "Analytics are currently enabled... DISABLING" | |
add_setting = {'settings': {'inactive_application': app_settings}} | |
del_setting = {'settings': {'active_application': {'eenivi': None}}} | |
else: | |
print "Analytics are currently disabled.. ENABLING" | |
add_setting = {'settings': {'active_application': old_app_settings}} | |
del_setting = {'settings': {'inactive_application': None}} | |
resp = session.post("{}/device".format(host), data={'id': esn, 'camera_settings_add': json.dumps(add_setting), 'camera_settings_delete': json.dumps(del_setting)}) | |
session.post("{}/aaa/switch_account".format(host), data={}) | |
print "Back in master account" | |
# For reference you'll be working on the 'active_application' json | |
# located at 'camera_parameters/user_settings/settings' in the camera settings payload | |
""" | |
'active_application': { | |
'eenivi': { | |
'features': { | |
'intrusion-1': { <---- Intrusion is active | |
'ns': 103, | |
'regions': { | |
'500170420023818.000': { | |
'id': u'500170420023818.000', | |
'level': [u'1'], | |
'mode': [u'all'], | |
'name': u'New Region', | |
'objectclass': [u'any'], | |
'objectsize': {u'maxh': 0.5, | |
u'maxw': 0.5, | |
u'minh': 0.1, | |
u'minw': 0.1}, | |
'poly': [[0.614, | |
0.39501779359430605], | |
[0.914, | |
0.39501779359430605], | |
[0.914, | |
0.693950177935943], | |
[0.614, | |
0.693950177935943]], | |
'sensitivity': 0.8, | |
'throttle_hour_limit': 100, | |
'throttle_seconds': 900, | |
'throttle_type': 1, | |
'when': u'work', | |
'who': [u'ca0a5e02']}}}, | |
'linecross-1': { | |
'lines': { | |
'501210804075419.000': { | |
'alert_on_in': False, | |
'alert_on_out': False, | |
'id': u'501210804075419.000', | |
'line': [[0.1, | |
0.1], | |
[0.85, | |
0.5833333333333334]], | |
'line_type': u'crossing', <----- crossing is installed | |
'name': u'New Line', | |
'objectclass': [u'any'], | |
'vector': u'up'}, | |
'501210806185659.000': { | |
'id': u'501210806185659.000', | |
'line': [[0.1, | |
0.1], | |
[0.85, | |
0.4444444444444444]], | |
'line_type': u'counting', <------ counting is installed | |
'name': u'New Line', | |
'objectclass': [u'any'], | |
'vector': u'up'}}, | |
'ns': 101}, | |
'object-1': { | |
'ns': 102, | |
'objectsize': {u'maxh': 0.5, | |
u'maxw': 0.5, | |
u'minh': 0.1, | |
u'minw': 0.1}, | |
'sensitivity': 0.8}}, | |
'log_level': 3}}, | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment