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) |
Job aborted
#!/usr/bin/env bash
last_build_url=$(curl -s --user "$1:$2" "$3/api/json"|jq .lastBuild.url|sed -e 's/^"//' -e 's/"$//')
if [[ $(curl -s --user "$1:$2" "$last_build_url/api/json"| jq .result|sed -e 's/^"//' -e 's/"$//') = "ABORTED" ]]; then echo 0; else echo 1; fi
Job Status
if [ $(curl -s --user "$1:$2" "$3/api/json"| jq .color|sed -e 's/^"//' -e 's/"$//') = "disabled" ]; then echo 0; else echo 1; fi
```bash
Job stream
```bash
#!/usr/bin/env bash
code=`curl -sL --user "$1:$2" --connect-timeout 10 --max-time 30 -w "%{http_code}\\n" "$3/api/json" -o /dev/null`
if [[ "$code" = "200" ]]; then
curl -s --user "$1:$2" "$3/api/json"| jq ."$4"|jq length
elif [[ "$code" == 4* ]]; then
if [[ "$4" == upstreamProjects* ]]|| [[ "$4" == downstreamProjects* ]];then
echo 0
else
# curl -s --user "$1:$2" "$3/api/json"| jq ."$4"|jq length
echo 0
fi
else
echo "Response code $code from API"
fi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Jenkins Job checksum