Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import json
- import subprocess
- def getProcessOutput(cmd):
- process = subprocess.Popen(
- cmd,
- shell=True,
- stdout=subprocess.PIPE)
- process.wait()
- data, err = process.communicate()
- if not process.returncode:
- return data.decode('utf-8')
- else:
- print("Error:", err)
- return ""
- # grab the output
- cmd = "hustodemonsky komand"
- output = getProcessOutput(cmd, shell=True, stdout=subprocess.PIPE)
- data = json.loads(output)
- # sample output
- #{
- # "data": {[
- # {
- # "id": "1",
- # "count": 12098
- # },
- # {
- # "id": "2",
- # "count": "928347"
- # },
- # {
- # "id": "3",
- # "count": "45987"
- # },
- # { dalsie id, ktore ma nezaujimaju }
- # ]}
- #}
- result = ""
- exitcode = 0
- # zosrotuj vystup
- for value in data:
- if value.id == "1":
- if value.count >= 10000:
- result = "OK"
- else if value.count >= 5000:
- result = "WARNING"
- if exitcode < 1 :
- exitcode += 1
- else:
- result = "CRITICAL"
- if exitcode < 2 :
- exitcode += 1
- result = result + ": Prvy=" + value.count + ", ")
- else if value.id == "2":
- if value.count >= 800000:
- result = "OK"
- else if value.count >= 500000:
- result = "WARNING"
- if exitcode < 1 :
- exitcode += 1
- else:
- result = "CRITICAL"
- if exitcode < 2 :
- exitcode += 1
- result = result + ": Druhy=" + value.count + ", ")
- else if value.id == "3":
- if value.count >= 50000:
- result = "OK"
- else if value.count >= 40000:
- result = "WARNING"
- if exitcode < 1 :
- exitcode += 1
- else:
- result = "CRITICAL"
- if exitcode < 2 :
- exitcode += 1
- result = result + ": Treti=" + value.count + ", ")
- else:
- pass
- print(result)
- return exitcode
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement