Check status of the remote machines
Another lockdown effect. A useful script when one is not able to acess the server rooms often. A fast ping on all the ip addresses, and then post the report to the Slack channel.
Got inspired from
The original code at
My adaptation
machines = {"x.x.x.x": "machenie 1")
output = 'Machines pinged at\n'
output += datetime.datetime.now().strftime('%a, %d %b %Y, %H:%M:%S')
output += '\n'
for ip_address, name in our_computers.items():
resp = os.system("fping --quiet --interval=1 --vcount=2 --period=50 " + ip_address)
if resp == 0:
output += ip_address + ', ' + name + ' is up!\n'
else:
output += ip_address + ', ' + name + ', is down!\n'
data = '{\"text\":\"' + output + '\"}'
url = "https://hooks.slack.com/services/<Your-slack-key>>"
headers = {
'Content-Type': "application/json",
'cache-control': "no-cache"
}
requests.request("POST", url, data=data, headers=headers)