Advertisement
BinaryJacob

Ansigle report

Jan 22nd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.70 KB | None | 0 0
  1. #!/usr/bin/python
  2. #python security-check-8.py  -i /etc/ansible/inventories/generic/static/local/local.yml -f /etc/ansible/playbooks/patchman/log-check.yml
  3. import re
  4. import json
  5. from datetime import datetime as dt
  6. import subprocess
  7. import argparse
  8. import csv
  9. def gencsv(out):
  10.     with open("out1000.csv","w+") as fl:
  11.         temp=csv.writer(fl, delimiter=",")
  12.         temp.writerow(["IP", "HOSTNAME" , "OS VERSION" , "CPU USAGE", "MEMORY USAGE", "ANSIBLE VERSION"])
  13.         ips=[]
  14.         nid=[]
  15.         out = out.decode("utf-8")
  16.         print(out)
  17.         xx = out.split("\n")
  18.         for nli in xx:
  19.             if "ansible_default_ipv4.address" in nli:
  20.                 ipx=nli.split(":")[1]
  21.             ips.append(ipx.replace('"',''))
  22.             for line in xx:
  23.                 if "ansible_nodename" in line:
  24.                     node = line.split(":")[1]
  25.                 nid.append(node.replace('"',''))
  26.         out= out.replace("\n","")
  27.     for rowips in ips:
  28.         for nidrow in nid:
  29.             temp.writerow(["%s" %(rowips), "%s" %(rownid)])    
  30. #[u' controller', u' an1', u' controller', u' an1']
  31. """                for hs in nid:
  32.                   optx='ok: [%s] => {    "msg": "os version : "}'%hs.replace(" ","")
  33.            solx='ok: [%s] => {    "msg": "cpu usage: "}'%hs.replace(" ","")
  34.            zkx='ok: [%s] => {    "msg": "memory usage: "}'%hs.replace(" ","")
  35.                   ans='ok: [%s] => {    "msg": "ansible version: "}'%hs.replace(" ","")
  36.  
  37.  
  38.            ipx = ips[int(nid.index(hs))]
  39.            opt = ""
  40.            sol = ""
  41.            zk = ""
  42.            if optx in out:
  43.                opt = ""
  44.            else:
  45.            opt = ""
  46.            if solx in out:
  47.                sol = ""
  48.            else:
  49.            sol = ""
  50.            if zkx in out:
  51.            zk = ""
  52.            else:
  53.                zk = ""
  54.                   if ans in out:
  55.                       ans = ""
  56.                   else:
  57.                       ans = ""
  58.                  
  59.      # temp.writerow(["%s","%s","%s","%s","%s","%s" %(ipx,hs,opt,sol,zk,ans)])"""
  60.        #  temp.writerow(["%s" %(ipx), "%s" %(hst)])
  61.  
  62.  
  63. #store but its correct?
  64. #no kust controller must say...can u see difference with sample.xls
  65. def execute(fur,sur):
  66.         cmd2 = "ansible-playbook -i %s %s"%(fur,sur)
  67.         p = subprocess.Popen(cmd2, stdout=subprocess.PIPE, shell=True)  
  68.         out, err = p.communicate()
  69.         return(out)
  70. if __name__ == '__main__':
  71.     parser = argparse.ArgumentParser()
  72.     parser.add_argument("-i")
  73.     parser.add_argument("-f")
  74.     args = parser.parse_args()
  75.     if (args.i is not None) and (args.f is not None):
  76.         out = execute(args.i,args.f)
  77.         gencsv(out)
  78.     else:
  79.         print("Missing arguments .")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement