Skip to content

Instantly share code, notes, and snippets.

@gregbuehler
Created August 20, 2018 17:43
Show Gist options
  • Save gregbuehler/7413838aa5b2bd504de3a84d17fd64ee to your computer and use it in GitHub Desktop.
Save gregbuehler/7413838aa5b2bd504de3a84d17fd64ee to your computer and use it in GitHub Desktop.
Attempt to randomize d42 discovery schedules
#!/usr/bin/env python
import sys, os, getpass
import requests, json
import random
# suppress the warning about unverified https
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
D42_BASE_URL = "https://device42.example.com"
D42_USERNAME = "user"
D42_PASSWORD = "pass"
D42_AUTH = (D42_USERNAME, D42_PASSWORD)
#==
def random_time():
return "%02d:%02d" % (random.randint(0,23), random.randint(0,59))
def get_schedules():
r = requests.get("%s/api/1.0/auto_discovery/snmp_disc/" % D42_BASE_URL,
verify=False,
auth=D42_AUTH
)
if r.status_code != 200:
return []
return r.json()["jobs"]
def update_discovery_rule_snmp(name):
time = random_time()
payload = {
"name": name,
"schedule_time": time,
"schedule_days": "0,1,2,3,4,5,6"
}
print("Updating: %s @ %s" % (name, time))
r = requests.post("%s/api/1.0/auto_discovery/snmp_disc/" % D42_BASE_URL,
verify=False,
data=payload,
auth=D42_AUTH
)
if (r.status_code != 200):
print(r.status_code, r.json())
print()
#==
if __name__ == "__main__":
jobs = get_schedules()
for job in jobs:
update_discovery_rule_snmp(job['name'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment