summaryrefslogtreecommitdiff
blob: 85991a3a85f0643b8ebcb35883f570a7920e65ad (plain)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/python
# Header   : $Header: /usr/local/cvsroot/shyam/scripts/gard-v2.py,v 1.2 2008/08/27 10:43:01 shyam Exp $
# Purpose  : Script to automatically check new Gentoo rsync and distfile mirrors
# Author   : Shyam Mani <fox2mike@gentoo.org>
# Created  : 05 Jul 2008

# Dedicated to robbat2 aka Robin, for sparking off the idea ;)

import sys
import time
import os
import datetime
import subprocess
import logging

import check

rmaxlag=45
dmaxlag = 5.5 * 3600
relmaxlag = 2 * 3600

HOME = os.getenv('HOME')
reportpath = HOME + "/gentoo/mirrors/gard/reports"
bugurl = "http://bugs.gentoo.org/buglist.cgi?query_format=advanced&product=Mirrors&status_whiteboard_type=allwordssubstr&status_whiteboard=due&bug_status=ASSIGNED&columnlist=bug_id,opendate,bug_status,resolution,short_desc,status_whiteboard&ctype=csv"
fname = HOME + "/gentoo/open-mirror-bugs"

logformat = '%(levelname)s:\t%(message)s'
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, format=logformat)

def add_handler(logfile):
	file = logging.FileHandler(logfile)
	file.setLevel(logging.INFO)
	formatter = logging.Formatter(logformat)
	file.setFormatter(formatter)
	logging.getLogger('').addHandler(file)
	return file

def remove_handler(handler):
	logging.getLogger('').removeHandler(handler)

retcode5=subprocess.call(['/usr/bin/wget','-q','-T 30', '-O', fname, bugurl])
file=open(fname,'r')
logging.debug("Initializing G(entoo)A(utomated)R(sync)D(istfiles) checker script, version 2 (Katrina) - kicking mirror ass for Gentoo")

# Format of CSV = 234083,"2008-08-06 13:01:32","ASSIGNED",,"[rsync,distfiles|all] New mirror Cambrium BV (The Netherlands)","due:2008/09/01;dist:http://mirror.cambrium.nl/pub/os/linux/gentoo/|ftp://mirror.cambrium.nl/pub/os/linux/gentoo/|rsync://mirror.cambrium.nl/gentoo/;portage:mirror.cambrium.nl"

for line in file:
	line=line.replace("\n","")
	data=line.split(',')
	bugnum=data[0]
	swboard=data[5]
	if bugnum == "bug_id":
		continue
	else:
		details=swboard.split(';')
		duedate=details[0]
		duedate=duedate.replace("\"","")
		#print duedate
		urls=details[1].replace("dist:","")
		port=details[2].split(':')
		grsync=port[1].replace("\"","")
		temp=urls.split('|')
		http=temp[0]
		ftp=temp[1]
		drsync=temp[2]
		#print http
		#print ftp
		#print drsync
		#print grsync
		if len(http) > 0:
			boo=http.split('/')
			addy=boo[2]
		elif len(ftp) > 0:
			boo=ftp.split('/')
			addy=boo[2]
		else:
			addy=grsync
		#hdomain='/'+addy[2]
		if len(grsync) > 0:
			fname=reportpath+"/"+grsync
			if os.path.isdir(reportpath):
				pass
	        	else:
        	        	os.makedirs(reportpath)
			handler = add_handler(fname)
			info4=grsync+" wants to be a gentoo-portage mirror and is being checked as per Bug #"+bugnum
			logging.info(info4)
			target=grsync+"::gentoo-portage/metadata/timestamp.chk"
			retcode=subprocess.call(['rsync','-aqP','--no-motd','--contimeout=30',target,'.'])
			if retcode > 0:
				logging.error("return value of rsync during gentoo-portage check was "+str(retcode))
			else:	
				temp=open('timestamp.chk','r')
				ots=temp.readline()
				temp.close()
				#Keep timestamp as Fri, 04 Jul 2008 20:45:01, remove the +0000 since there doesn't seem to be a %z in python
				t1=time.mktime(time.strptime(ots.replace(" +0000",""), "%a, %d %b %Y %H:%M:%S "))
				lag=(time.mktime(time.gmtime())-t1)/60
				if lag > rmaxlag:
					error4 = "gentoo-portage mirror is lagging by over 40 mins, lag is : "+str(round(lag,2))+" mins"
					tstamp4 = "Timestamp on Mirror   : "+str(ots).strip()
					curtime4 = "Current time in UTC   : "+str(time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()))
					bugurl4 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate
					logging.error(error4)
					logging.info(tstamp4)
					logging.info(curtime4)
					logging.info(bugurl4)
				else:
					info4 = grsync+" is in sync, current delta : "+str(round(lag,2))+" mins"
					tstamp4 = "Timestamp on Mirror   : "+str(ots)
					curtime4= "Current time in UTC   : "+str(time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()))
					bugurl4 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate
					logging.info(info4)
					logging.info(tstamp4)
					logging.info(curtime4)
					logging.info(bugurl4)
				os.unlink('timestamp.chk')
			# New line for the prettiness
			logging.info('')
			remove_handler(handler)
		if len(http) > 0:
			fname=reportpath+"/"+addy
			if os.path.isdir(reportpath):
      				pass
        		else:
       				os.makedirs(reportpath)
			handler = add_handler(fname)
			info5 = addy+" wants to be distfiles mirror and is being checked as per Bug #"+bugnum+ " over http"
			logging.info(info5)

			synced = True
			if check.DistfilesCheck(http).check(dmaxlag) is not True:
				synced = False
			if check.ReleasesCheck(http).check(relmaxlag) is not True:
				synced = False
			if synced:
				logging.info(addy + ' is in sync')
			else:
				logging.info(addy + ' is out of sync')

			bugurl1 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate
			logging.info(bugurl1)

			# New line for the prettiness
			logging.info('')
			remove_handler(handler)
		if len(ftp) > 0:
			fname=reportpath+"/"+addy
			if os.path.isdir(reportpath):
       				pass
       			else:
       				os.makedirs(reportpath)
			add_handler(fname)
			info6 = addy+" wants to be an distfiles mirror and is being checked as per Bug #"+bugnum+ " over ftp"
			logging.info(info6)

			synced = True
			if check.DistfilesCheck(ftp).check(dmaxlag) is not True:
				synced = False
			if check.ReleasesCheck(ftp).check(relmaxlag) is not True:
				synced = False
			if synced:
				logging.info(addy + ' is in sync')
			else:
				logging.info(addy + ' is out of sync')

			bugurl1 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate
			logging.info(bugurl1)

			# New line for the prettiness
			logging.info('')
			remove_handler(handler)
		if len(drsync) > 0:
			fname=reportpath+"/"+addy
			if os.path.isdir(reportpath):
	       			pass
      			else:
               			os.makedirs(reportpath)
			add_handler(fname)
			info7 = addy+" wants to be an distfiles mirror and is being checked as per Bug #"+bugnum+ " over rsync"
			logging.info(info7)
			target=drsync+"/distfiles/timestamp.chk"
			retcode4=subprocess.call(['rsync','-aqP','--no-motd','--contimeout=30',target,'.'])
			if retcode4 > 0:
				logging.error("return value of rsync during distfiles check was "+str(retcode4))
			else:
				temp=open('timestamp.chk','r')
				ots=temp.readline()
				temp.close()
				t1=time.mktime(time.strptime(ots.replace(" +0000",""), "%a, %d %b %Y %H:%M:%S "))
				lag=(time.mktime(time.gmtime())-t1)/(60*60)
				if lag > dmaxlag:
					error7 = "Mirror is lagging by over 5.5 hours, difference is : "+str(round(lag,2))+" hours"
					tstamp7 = "Timestamp on Mirror   : "+str(ots).strip()
					curtime7= "Current time in UTC   : "+str(time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()))
					bugurl7 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate
					logging.error(error7)
					logging.info(tstamp7)
					logging.info(curtime7)
					logging.info(bugurl7)
				else:
					info7 = addy+" is in sync, current lag : "+str(round(lag,2))+" hours"
					tstamp7 = "Timestamp on Mirror   : "+str(ots)
					curtime7 = "Current time in UTC   : "+str(time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()))
					bugurl7 = "Bug URL : https://bugs.gentoo.org/"+bugnum+" , "+duedate
					logging.info(info7)
					logging.info(tstamp7)
					logging.info(curtime7)
					logging.info(bugurl7)
				os.unlink('timestamp.chk')
			# New line for the prettiness
			logging.info('')
			remove_handler(handler)