def uptime(): """ :return uptime of the system :return {"output": output, "error": error} """ LOG.info("Checking uptime") output = "" try: output, error = execute("uptime") except Exception, e: LOG.exception(e) error = str(e)
def running_process(): """ Get all the process running on the system :return: array of process :return {"output": <array>, "error": error} """ LOG.info("Getting all the process running") try: cmd = "ps -eo args" output, error = execute(cmd) plist = output.strip().split("\n") return {"output": plist, "error": error} except Exception, e: return {"output": [], "error": str(e)}
def netstat(): """ :return netstat output of the system :return {"output": <array>, "error": error} """ LOG.info("Getting netstat/ss output") ## TO DO #cmd = "netstat -antp" try: cmd = "ss -t -u -a" out, err = execute(cmd) if out: stats = out.strip().split("\n") output = parseNetstat(stats) return {"output": output, "error": err} else: LOG.error("[%s] command failed" %cmd) return {"output":[], "error": err} except Exception, e: return {"output": [], "error": str(e)}
def check_process(process): """ :param process :return usage of the process on the system :return {"output": <array>, "error": error} """ LOG.info("Getting [%s] process information from ps" % process) try: cmd = "ps -eo user,pid,pcpu,pmem,lstart,args | grep -i %s | grep -v grep" % \ process out, err = execute(cmd) if out: plist = out.strip().split("\n") output = parseProcesses(plist) return {"output": output, "error": err} else: LOG.error("[%s] process not found" %process) return {"output":[], "error": err} except Exception, e: LOG.exception(e) return {"output": [], "error": str(e)}