Skip to content

Instantly share code, notes, and snippets.

@pkulev
Created November 23, 2015 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkulev/1f3ad493a0f70c601634 to your computer and use it in GitHub Desktop.
Save pkulev/1f3ad493a0f70c601634 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import argparse
import os
import sys
from subprocess import check_output, CalledProcessError
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("-p", "--pretend", action="store_true", help="Don't change file.")
return parser.parse_args()
def _get_pid(name):
try:
return map(int, check_output(["pidof", name]).split())
except CalledProcessError:
return []
def check_status(name="java"):
pid = _get_pid(name)
return "<h2>status: <u>{0}</u></h2>\n".format("running" if pid else "down")
def check_uptime():
return "<h2>uptime: {0}</h2>".format(check_output(["uptime"]))
def main():
args = parse_args()
index_path = "/var/www/mcmon/index.html"
checkers = [
check_uptime,
check_status]
if args.pretend:
for checker in checkers:
print(checker())
sys.exit(os.EX_OK)
with open(index_path, "w") as fd:
for checker in checkers:
fd.write(checker())
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment