Skip to content

Instantly share code, notes, and snippets.

@jamil666
Last active November 13, 2019 13:00
Show Gist options
  • Save jamil666/60accb39841231441c14e4e739e4a9be to your computer and use it in GitHub Desktop.
Save jamil666/60accb39841231441c14e4e739e4a9be to your computer and use it in GitHub Desktop.
import requests
from hpe3parclient import client, exceptions
username = 'username'
password = 'password'
# Storage IP
ip_address = 'IP'
Storage = 'Storage Name'
# Connecting to API
cl = client.HPE3ParClient("https://IP:8080/api/v1")
# Set the SSH authentication options for the SSH based calls.
cl.setSSHOptions(ip_address, username, password)
try:
cl.login(username, password)
print("Connected to 3PAR Storage")
except exceptions.HTTPUnauthorized as ex:
print("Login failed.")
# Total and Free space on storage in TB
HDD_Total = cl.getOverallSystemCapacity()['FCCapacity']['totalMiB'] / 1024 / 1024
HDD_Free = round(cl.getOverallSystemCapacity()['FCCapacity']['freeMiB'] / 1024 / 1024, 2)
SSD_Total = cl.getOverallSystemCapacity()['SSDCapacity']['totalMiB'] / 1024 / 1024
SSD_Free = round(cl.getOverallSystemCapacity()['SSDCapacity']['freeMiB'] / 1024 / 1024, 2)
# Telegram Bot URL
URL = 'https://api.telegram.org/bot<chatid>/'
# Get Bot Chat ID
def GetID():
url = URL + 'getUpdates'
r = requests.get(url)
id = r.json()['result'][-1]['message']['chat']['id']
return id
# Send message to Teleram bot
def SendMessage(id, text = ''):
url = URL + 'sendMessage'
text = {'chat_id': id, 'text': text}
r = requests.post(url, json=text)
return r.json()
if HDD_Free >= 2 or SSD_Free >= 2:
Body = 'Free space on storage {} is running out. Available space on FC is {} TB and on SSD is {} TB'.format(Storage, HDD_Free, SSD_Free)
SendMessage(id=GetID(), text=Body)
cl.logout()
print("logout worked")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment