def main(): ## Set input variables fields = { "apikey": { "type": "str", "required": True, "no_log": True }, "uptimeid": { "type": "str", "required": True }, } module = AnsibleModule(argument_spec=fields, supports_check_mode=False) ## Assign params to more usable variables api_key = module.params['apikey'] arg_uptimeid = module.params['uptimeid'] client = pingdompy.Client(apikey=api_key) delete = client.delete_check(arg_uptimeid) ## Return verification to ansible module.exit_json(changed=True, response=verify)
def main(): ## Set input variables fields = { "apikey": { "type": "str", "required": True, "no_log": True }, "uptimeid": { "type": "str", "required": True }, "name": { "type": "str", "required": True }, "start": { "type": "str", "required": True }, "duration": { "type": "str", "required": True }, } module = AnsibleModule(argument_spec=fields, supports_check_mode=False) ## Assign params to more usable variables api_key = module.params['apikey'] maint_name = module.params['name'] start_time = module.params['start'] duration_time = module.params['duration'] arg_uptimeid = module.params['uptimeid'] client = pingdompy.Client(apikey=api_key) ## Calculates the start and end times for the window start = datetime.datetime.now() + datetime.timedelta( minutes=int(start_time)) end = start + datetime.timedelta(minutes=int(duration_time)) ## Creates window and converts times to something pingdom accepts window = client.create_maintenance({"description": maint_name, \ "from": int(time.mktime(start.timetuple())), "to": int(time.mktime(end.timetuple())), "uptimeids": arg_uptimeid}) ## Verification of window creation verify = client.get_maintenance(window['id']) ## Return verification to ansible module.exit_json(changed=True, response=verify)
def main(): ## Set input variables for ansible fields = { "apikey": { "type": "str", "required": True, "no_log": True }, "uptimeid": { "type": "str", "required": True }, "addtags": { "type": "str", "required": False }, "tags": { "type": "str", "required": False }, "host": { "type": "str", "required": False }, "responsetime_threshold": { "type": "str", "required": False }, "resolution": { "type": "str", "required": False }, "teamids": { "type": "str", "required": False }, "paused": { "type": "str", "required": False }, } ###### Further variables could be added above if necessary module = AnsibleModule(argument_spec=fields, supports_check_mode=False) ## Removes keys Pingdom won't accept from the dict api_key = module.params.pop("apikey") check = module.params.pop("uptimeid") client = pingdompy.Client(apikey=api_key) ## Logic to enable the change dictionary creation changes = {} for x in module.params: if module.params.get(x) != None: changes[x] = module.params.get(x) else: continue ###### If a key is given a blank value and passed to pingdom, it will clear that field to default ###### so a system could be added above where if a keyword like 'CLEAR!' is passed in as a ###### variable, it will send pingdom a blank key pair like: "paused": "" ## Creates the update and returns an output dependant message update = client.update_check(check, changes) ## Sends response back upto ansible module.exit_json( ## if update_check returns a list, then the update worked changed=isinstance(update, list), response=update)
def main(): ## Set input variables fields = { "apikey": { "type": "str", "required": True, "no_log": True }, "host": { "type": "str", "required": True }, "name": { "type": "str", "required": True }, "protocol": { "type": "str", "required": True }, "tags": { "type": "str", "required": False }, "timing": { "type": "str", "required": False }, "port": { "type": "str", "required": False }, "encryption": { "type": "str", "required": False }, "verify_certificate": { "type": "str", "required": False }, "probe_filters": { "type": "str", "required": False }, "shouldcontain": { "type": "str", "required": False }, "integrationids": { "type": "str", "required": False }, "url": { "type": "str", "required": False }, "pause": { "type": "str", "required": False }, } ###### Further variables could be added above and below to allow ###### for more complex checks to be added module = AnsibleModule(argument_spec=fields, supports_check_mode=False) ## Assign params to more usable variables api_key = module.params['apikey'] check_host = module.params['host'] check_name = module.params['name'] check_proto = module.params['protocol'] check_tags = module.params['tags'] check_timing = module.params['timing'] check_port = module.params['port'] check_encryption = module.params['encryption'] check_verification = module.params['verify_certificate'] check_filters = module.params['probe_filters'] check_contain = module.params['shouldcontain'] check_ids = module.params['integrationids'] check_url = module.params['url'] check_pause = module.params['pause'] client = pingdompy.Client(apikey=api_key) ## Creates the check and returns the new checks id + name check = client.create_check({"host": check_host, "name": check_name, \ "type": check_proto, "tags": check_tags, "resolution": check_timing, \ "verify_certificate": check_verification, "probe_filters": check_filters, \ "shouldcontain": check_contain, "integrationids": check_ids, "url": check_url, \ "port": check_port, "encryption": check_encryption, "paused": check_pause}) ## Returns verification to ansible module.exit_json(changed=True, response=check)