mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-06 13:25:51 +01:00
update monitor
This commit is contained in:
@@ -2945,3 +2945,28 @@ class CloudManager:
|
|||||||
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
|
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
|
||||||
final_json = json.dumps(final_dic)
|
final_json = json.dumps(final_dic)
|
||||||
return HttpResponse(final_json)
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
def UptimeMonitor(self):
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
del self.data['controller']
|
||||||
|
del self.data['serverUserName']
|
||||||
|
del self.data['serverPassword']
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
CloudConfigPath = '/home/cyberpanel/cloud'
|
||||||
|
writeToFile = open(CloudConfigPath, 'w')
|
||||||
|
writeToFile.write(json.dumps(self.data))
|
||||||
|
writeToFile.close()
|
||||||
|
|
||||||
|
execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/ClusterManager.py --function UptimeMonitor --type All"
|
||||||
|
ProcessUtilities.executioner(execPath)
|
||||||
|
|
||||||
|
final_json = json.dumps({'status': 1})
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
|
except BaseException as msg:
|
||||||
|
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
|
||||||
|
final_json = json.dumps(final_dic)
|
||||||
|
return HttpResponse(final_json)
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ def router(request):
|
|||||||
return cm.DetachCluster()
|
return cm.DetachCluster()
|
||||||
elif controller == 'DebugCluster':
|
elif controller == 'DebugCluster':
|
||||||
return cm.DebugCluster()
|
return cm.DebugCluster()
|
||||||
|
elif controller == 'UptimeMonitor':
|
||||||
|
return cm.UptimeMonitor()
|
||||||
elif controller == 'FetchMasterBootStrapStatus':
|
elif controller == 'FetchMasterBootStrapStatus':
|
||||||
return cm.FetchMasterBootStrapStatus()
|
return cm.FetchMasterBootStrapStatus()
|
||||||
elif controller == 'FetchChildBootStrapStatus':
|
elif controller == 'FetchChildBootStrapStatus':
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ from plogical.mysqlUtilities import mysqlUtilities
|
|||||||
class ClusterManager:
|
class ClusterManager:
|
||||||
|
|
||||||
LogURL = "https://cloud.cyberpanel.net/HighAvailability/RecvData"
|
LogURL = "https://cloud.cyberpanel.net/HighAvailability/RecvData"
|
||||||
|
UptimeURL = "https://cloud.cyberpanel.net/servers/UptimeReport"
|
||||||
ClusterFile = '/home/cyberpanel/cluster'
|
ClusterFile = '/home/cyberpanel/cluster'
|
||||||
|
CloudConfig = '/home/cyberpanel/cloud'
|
||||||
vhostConfPath = '/usr/local/lsws/conf/vhosts'
|
vhostConfPath = '/usr/local/lsws/conf/vhosts'
|
||||||
|
|
||||||
def __init__(self, type):
|
def __init__(self, type):
|
||||||
@@ -27,14 +29,19 @@ class ClusterManager:
|
|||||||
ipData = f.read()
|
ipData = f.read()
|
||||||
self.ipAddress = ipData.split('\n', 1)[0]
|
self.ipAddress = ipData.split('\n', 1)[0]
|
||||||
##
|
##
|
||||||
|
if os.path.exists(ClusterManager.ClusterFile):
|
||||||
self.config = json.loads(open(ClusterManager.ClusterFile, 'r').read())
|
self.config = json.loads(open(ClusterManager.ClusterFile, 'r').read())
|
||||||
|
elif os.path.exists(ClusterManager.CloudConfig):
|
||||||
|
self.config = json.loads(open(ClusterManager.CloudConfig, 'r').read())
|
||||||
|
|
||||||
self.type = type
|
self.type = type
|
||||||
|
|
||||||
def PostStatus(self, message):
|
def PostStatus(self, message):
|
||||||
try:
|
try:
|
||||||
finalData = {'name': self.config['name'], 'type': self.type, 'message': message, 'token': self.config['token']}
|
finalData = {'name': self.config['name'], 'type': self.type, 'message': message, 'token': self.config['token']}
|
||||||
resp = requests.post(ClusterManager.LogURL, data=json.dumps(finalData), verify=False)
|
resp = requests.post(ClusterManager.LogURL, data=json.dumps(finalData), verify=False)
|
||||||
# logging.writeToFile(resp.text + '[info]')
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.writeToFile(resp.text + '[info]')
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
logging.writeToFile('%s. [31:404]' % (str(msg)))
|
logging.writeToFile('%s. [31:404]' % (str(msg)))
|
||||||
|
|
||||||
@@ -85,7 +92,6 @@ class ClusterManager:
|
|||||||
writeToFile = open(cronPath, 'a')
|
writeToFile = open(cronPath, 'a')
|
||||||
writeToFile.write('*/5 * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/ClusterManager.py --function CreatePendingVirtualHosts --type Child\n')
|
writeToFile.write('*/5 * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/ClusterManager.py --function CreatePendingVirtualHosts --type Child\n')
|
||||||
writeToFile.close()
|
writeToFile.close()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
writeToFile = open(ClusterPath, 'w')
|
writeToFile = open(ClusterPath, 'w')
|
||||||
writeToFile.write(config['ClusterConfigMaster'])
|
writeToFile.write(config['ClusterConfigMaster'])
|
||||||
@@ -133,6 +139,12 @@ class ClusterManager:
|
|||||||
except:
|
except:
|
||||||
self.PostStatus('Failed to add Firewall rules, manually open the required ports..')
|
self.PostStatus('Failed to add Firewall rules, manually open the required ports..')
|
||||||
|
|
||||||
|
## Change permissions of cluster config path
|
||||||
|
|
||||||
|
command = 'chmod 600 %s' % (ClusterConfigPath)
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
self.PostStatus('Successfully attached to cluster. [200]')
|
self.PostStatus('Successfully attached to cluster. [200]')
|
||||||
|
|
||||||
@@ -361,6 +373,40 @@ password=%s""" % (rootdbpassword, rootdbpassword)
|
|||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
self.PostStatus('Failed to debug cluster, error %s [404].' % (str(msg)))
|
self.PostStatus('Failed to debug cluster, error %s [404].' % (str(msg)))
|
||||||
|
|
||||||
|
def UptimeMonitor(self):
|
||||||
|
try:
|
||||||
|
|
||||||
|
CentOSPath = '/etc/redhat-release'
|
||||||
|
|
||||||
|
if os.path.exists(CentOSPath):
|
||||||
|
cronPath = '/var/spool/cron/root'
|
||||||
|
else:
|
||||||
|
cronPath = '/var/spool/cron/crontabs/root'
|
||||||
|
|
||||||
|
writeToFile = open(cronPath, 'a')
|
||||||
|
|
||||||
|
writeToFile.write('*/3 * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/ClusterManager.py --function Uptime --type All\n')
|
||||||
|
writeToFile.close()
|
||||||
|
|
||||||
|
|
||||||
|
command = 'systemctl restart cron'
|
||||||
|
ProcessUtilities.normalExecutioner(command)
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
except BaseException as msg:
|
||||||
|
logging.writeToFile('Error while setting up Uptime cron. Error %s' % (str(msg)))
|
||||||
|
|
||||||
|
def Uptime(self):
|
||||||
|
try:
|
||||||
|
finalData = {'name': self.config['name'], 'token': self.config['token']}
|
||||||
|
resp = requests.post(ClusterManager.LogURL, data=json.dumps(finalData), verify=False)
|
||||||
|
if os.path.exists(ProcessUtilities.debugPath):
|
||||||
|
logging.writeToFile(resp.text + '[Uptime:info]')
|
||||||
|
except BaseException as msg:
|
||||||
|
logging.writeToFile('%s. [31:404]' % (str(msg)))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
||||||
@@ -387,6 +433,10 @@ def main():
|
|||||||
uc.PingNow()
|
uc.PingNow()
|
||||||
elif args.function == 'DebugCluster':
|
elif args.function == 'DebugCluster':
|
||||||
uc.DebugCluster()
|
uc.DebugCluster()
|
||||||
|
elif args.function == 'UptimeMonitor':
|
||||||
|
uc.UptimeMonitor()
|
||||||
|
elif args.function == 'Uptime':
|
||||||
|
uc.Uptime()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user