Created
August 15, 2018 08:39
-
-
Save weldpua2008/b4e38d3a102a70a94eacae655a04d207 to your computer and use it in GitHub Desktop.
Example LLD of Jenkins Jobs for Zabbix
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
#!/usr/bin/env python | |
################################################################################### | |
# desc: simple tool use to monitoring and discover jenkins jobs | |
################################################################################### | |
# Author Valeriy SOloviov <[email protected]> | |
# - 21.12.2017 | |
############################################################# | |
import json | |
import requests | |
USERNAME = '[email protected]' | |
PASSWORD = '' | |
JENKINS_URL = 'https://jenkins:8443/jenkins/' | |
def discovery(url): | |
# print url | |
data = [] | |
try: | |
jobs = requests.get(url, auth=(USERNAME, PASSWORD)) | |
json_data = json.loads(jobs.text) | |
if "buildable" in json_data and json_data["buildable"] == True: | |
if 'fullName' in json_data and 'url' in json_data: | |
data.append({"{#JOBNAME}": json_data['fullName'],"{#JOBURL}": json_data['url']}) | |
elif "jobs" in json_data: | |
for job in json_data["jobs"]: | |
if "url" in job: | |
data += discovery(job["url"]+'api/json') | |
except Exception as e: | |
return [] | |
return data | |
_data = discovery(JENKINS_URL+'api/json') | |
data = {"data": _data } | |
print json.dumps(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Job aborted
Job Status