-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.py
94 lines (67 loc) · 3.07 KB
/
check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from github import Github
from prometheus_client import start_http_server, Info, Gauge
import time
import docker
import re
import json
import pprint
import subprocess
import requests
import gitlab
pp = pprint.PrettyPrinter(indent=4)
client = docker.from_env()
PRIVATE_TOKEN_GITLAB = ''
PRIVATE_TOKEN_GITHUB = ''
PRIVATE_TOKEN_GITLABCOM = ''
headerGitLab = {
'PRIVATE-TOKEN': PRIVATE_TOKEN_GITLAB
}
def isVersionEqual(yourVersionString, otherVerionStringJsonList, isJson):
if(isJson):
result = filter(lambda x: not "pre" in x["name"] and not "rc" in x["name"],otherVerionStringJsonList)
otherVersionString = result.__next__()["name"]
else:
result = filter(lambda x: not "pre" in x.name and not "rc" in x.name, otherVerionStringJsonList)
otherVersionString = result.__next__().name
return ("v"+yourVersionString).__eq__(otherVersionString)
def isVersionEqual2(yourVersionString, otherVerionStringJsonList):
result = filter(lambda x: not "pre" in x["name"] and not "rc" in x["name"],otherVerionStringJsonList)
otherVersionString = result.__next__()["name"]
return ("v"+yourVersionString).__eq__(otherVersionString)
def isDockerLatest():
github = Github(PRIVATE_TOKEN_GITHUB)
gitHubVersion = github.get_repo("docker/docker-ce").get_releases()[0].title
clientVersionWithTag = client.version()["Version"]
clientVersionRegex = re.search("[0-9\.]*",clientVersionWithTag)
clientVersion = clientVersionRegex.group(0)
if clientVersion.__eq__(gitHubVersion):
return True
else:
return False
def isGitlabLatest():
r = requests.get('http://localhost:8000/api/v4/version', headers=headerGitLab)
gitlabLocalVersionString = json.loads(r.text)["version"]
requestServer = json.loads(requests.get('https://api.github.com/repos/gitlabhq/gitlabhq/tags').text)
return isVersionEqual(gitlabLocalVersionString, requestServer, isJson=True)
def isGitlabRunnerLatest():
allRunners = json.loads(requests.get('http://localhost:8000/api/v4/runners', headers=headerGitLab).text)
gl = gitlab.Gitlab('http://gitlab.com', private_token=PRIVATE_TOKEN_GITLABCOM)
for runnerFromAll in allRunners:
runner = json.loads(requests.get('http://localhost:8000/api/v4/runners/'+str(runnerFromAll["id"]), headers=headerGitLab).text)
return isVersionEqual(runner["version"], gl.projects.get(250833).releases.list(), isJson=False)
#print(isGitlabLatest())
#print(isDockerLatest())
#print(isGitlabRunnerLatest())
if __name__ == '__main__':
# Start up the server to expose the metrics.
start_http_server(9999)
# Generate some requests.
while True:
g = Gauge("is_gitlab_latest", "0 if gitlab needs to be updated else 1")
g.set(isGitlabLatest())
g = Gauge("is_docker_latest", "0 if docker needs to be updated else 1")
g.set(isDockerLatest())
g = Gauge("is_gitlab_runner_latest", "0 if gitlab-runner needs to be updated else 1")
g.set(isGitlabRunnerLatest())
print("asgssag")
time.sleep(60*10)