#!/usr/bin/env python3 import os MAX_LOAD = 0.2 def topmsg(): topmsg = os.popen("top -b -n 1").readlines()[0:5] return topmsg def osload(loadstr): load_num = loadstr.split('load average: ')[1].split(", ")[0] return float( load_num ) > MAX_LOAD def sendmsg(msg_list): msg_list.insert(0, "cpu load alert rnrn") return "".join(msg_list) def sendtoxmpp(msg): command_str = " xmpp-message --jabberid ryi@jabber.fr --password psdpsd --receiver rayzhitch.org --message '" + msg.replace("'", "'") + "'" tomsg = os.popen(command_str).read() return tomsg if __name__ == '__main__': msg = topmsg() if osload(msg[0]) : print( sendtoxmpp( sendmsg(msg) )) else : print("it's nothing")