最初のパスはすべて正常に機能しますが、2回目の実行ではAttributeErrorが発生します:インスタンスには__ addinfourl call__メソッドがなく、何が問題なのかわかりません
最初のパスTrueStatus:OK
2番目のパスファイル"D:\ python \ New Status \ status.py"、行124、印刷mainstatus.bite()ファイル "D:\ python \ New Status \ status.py"、行109、バイトs = file ("cc.beat")AttributeError:addinfourlインスタンスには呼び出しメソッドがありません
基本的には、サーバーのステータスをチェックし、別のプロセスがアクティブであることを確認するために使用します
failure = True
servestatus = False
def log():
a=open ("Status.failures","a")
now = datetime.now()
tiempo = str (now) +" - Error\n"
a.write(tiempo)
a.close ()
class mainstatus(object):
@staticmethod
def xmlstatus():
try:
file = urllib2.urlopen('http://192.168.1.110:9900/admin/xmlstatus?user=&password=')
data = file.read()
file.close()
dom = parseString(data)
xmlTag = dom.getElementsByTagName('Status')[0].toxml()
xmlData=xmlTag.replace('<Status>','').replace('</Status>','')
if xmlTag == "<Status>OK</Status>":
stat = True
except:
stat= False
return stat
@staticmethod
def hola():
x = "test"
return x
@staticmethod
def internet(url):
try:
response=urllib2.urlopen(url,timeout=1)
return True
except urllib2.URLError as err: pass
return False
@staticmethod
def heartbeat():
a=open ("heart.beat","w")
now = datetime.now()
tiempo = str (now.minute)
a.write(tiempo)
a.close ()
@staticmethod
def push(mensaje):
#Miguel
conn = httplib.HTTPSConnection("api.pushover.net:443")
conn.request("POST", "/1/messages.json",
urllib.urlencode({
"token": "",
"user": "",
"message": mensaje,
}), { "Content-type": "application/x-www-form-urlencoded" })
conn.getresponse()
#Gerswin
conn = httplib.HTTPSConnection("api.pushover.net:443")
conn.request("POST", "/1/messages.json",
urllib.urlencode({
"token": "",
"user": "",
"message": mensaje,
}), { "Content-type": "application/x-www-form-urlencoded" })
conn.getresponse()
@staticmethod
def colam():
cola = 0
for root, dirs, files in os.walk("\\\\Server0\\smsdata\\Q"):
for file in files:
if file.endswith('.req'):
cola += 1
@staticmethod
def wol():
HOST = "192.168.1.1"
user = "root"
password = "16745665"
tn = telnetlib.Telnet(HOST)
tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("/usr/sbin/wol -i 192.168.1.255 -p 7 00:11:25:36:08:FE\n")
tn.write("exit\n")
tn.read_all()
@staticmethod
def bite():
now = datetime.now()
tiempo = (now.minute)
s = file("cc.beat")
status = int(s.readline())
s.close()
vivo = tiempo - status
if (vivo > 0):
return False
else:
return True
count = 5
print "Server Status Check: Runing..."
while (count < 9):
time.sleep(2)
print mainstatus.bite()
pulso = True
if pulso == False:
#os.startfile('check.exe')
print "activa"
else:
pass
status = mainstatus.internet("http://192.168.1.110:9900")
mainstatus.heartbeat()
if status == True:
if mainstatus.xmlstatus() == True:
print '\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bStatus:OK',
if failure == True:
accion = os.system('net stop "NowSMS"')
file = urllib2.urlopen('http://sql.gerswin.com/status.php?status=OK')
data = file.read()
file.close()
failure = False
if mainstatus.colam() >= 20 and servestatus == False:
accion = os.system('net start "NowSMS"')
mainstatus.push("Server Overload, Server 2 Running")
servestatus = True
else:
if mainstatus.colam() < 20 and servestatus == True:
mainstatus.push("Stoping Server 2")
accion = os.system('net stop "NowSMS"')
servestatus = False
file = urllib2.urlopen('http://sql.gerswin.com/status.php?status=OK')
data = file.read()
file.close()
else:
print '\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bStatus: Modem Failure',
mainstatus.wol()
if servestatus == False:
accion = os.system('net start "NowSMS"')
mainstatus.push("Modem Failure, Server 2 Running")
log()
file = urllib2.urlopen('http://sql.gerswin.com/status.php?status=2')
data = file.read()
file.close()
servestatus = True
else:
print "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\bStatus: Fallo Server",
mainstatus.wol()
if servestatus == False:
accion = os.system('net start "NowSMS"')
file = urllib2.urlopen('http://192.168.1.110:9900?ok=no')
data = file.read()
file.close()
log()
mainstatus.push("Server Failure, Server 2 Running")
servestatus = True