1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
# Fichier smdb_beta.py
"""
Licence : GNU General Public Licence
Description :
A partir d'un fichier en entrée .RECORD récupérer les
informations recherchées et les exporter dans un fichier csv
pour son exploitation.
"""
#~ import sys
import os
import os.path as OP
import time
import subprocess
import shlex
import gettext
import argparse
from xml.dom import minidom
# svp, prenez 5 minutes pour lire la PEP 8 Python :
# http://legacy.python.org/dev/peps/pep-0008/
# variables globales
info_file = OP.expanduser("~/.cmdb")
# Intervalles de mise à jour (en heures)
update_interval = 24
# liste pour stocker les resulats du parsing
#~ list = [row[0],row[1], row[2], row[3], row[4]]
liste_resultats = [] # comme ça ?
#~ app_dir = OP.dirname(sys.argv[0])
app_dir = OP.abspath(OP.dirname(__file__))
localdir = OP.join(app_dir, "locale")
gettext.install("messages", localdir)
# fonctions
def help():
"""
Affichage de l'utilisation du programme
"""
# NON, voir https://docs.python.org/2.7/library/argparse.html
pass
#~ print(_("""\
#~ usage: {0} <votre recherche>
#~ -p ou --parsing : parsing du fichier .record
#~ -g ou --generation csv : generation du fichier de sortie en csv
#~ -h ou --help : affiche ce message d'aide
#~ """).format(sys.argv[0])
#~ )
#~ exit(1)
def print_choice_dialog():
print("---")
print("Application CMDB")
print("Version Beta")
print("Developpeur XXX")
def check_choice(nbchoice):
"""
Vérification de la réponse de l'utilisateur
"""
while True:
try:
choice = input(_("Entrez le choix voulu:)")).split(" ")
except KeyboardInterrupt:
print("Okay, bye bye!")
exit(0)
if choice[0] == "+":
return "+"
for i in choice:
if i.isdigit():
if int(i) in range(nbchoice+1):
return choice
else:
break
# end if
else:
break
# end if
# end for
print_choice_dialog()
# end while
# end def
def parse_xml():
"""
parsing du fichier .record
"""
#doc = minidom.parse(......)
nodes = doc.getElementsByTagName("log start")
for node in nodes:
print node.firstChild.nodeValue
nodes = doc.getElementsByTagName("EXEC start")
for node in nodes:
print node.firstChild.nodeValue
#Recuperatiuon des Attributes pour la balise log start
#doc = minidom.parse(......)
nodes = doc.getElementsByname("log start")
for node in nodes:
if node.attributes.has_key("log"):
#print node.attributes["log"].value
row[0]
if node.attributes.has_key("start"):
#print node.attributes["start"].value
row[1]
if node.attributes.has_key("severity"):
#print node.attributes["severity"].value
row[2]
if node.attributes.has_key("CMD"):
#print node.attributes["CMD"].value
row[3]
#Recuperation des attributes pour la balise EXEC start
node = doc.getElementsByname("EXEC start")
for node in nodes:
if node.attributes.has_key("start"):
#print node.attributes.has_key("start")
row[1]
if node.attributes.has_key("duration"):
#print node.attributes.has_key("duration")
row[2]
if node.attributes.has_key("CMD"):
#print node.attributes.has_key("CMD")
row[3]
if node.attributes.has_key("RESULT"):
#print node.attributes.has_key("RESULT")
row[4]
def csv():
"""
génération fichier csv avec le dialecte d'excel
"""
data = [
[
"EXEC/ log", "start", "duration/ severity", "CMD / event",
"RESULT"
]
]
fname = "cmdb_out.csv"
# NON, voir https://docs.python.org/2.7/library/csv.html
pass
#~ file = open("fname", "rb")
#~ try:
#~ reader = csv.reader(file)
#~ writer.writerows(data)
#~ for row in writer:
#~ print row[0],row[1],row[2],row[3],row[4]
#~ finally:
#~ fd.close()
def main() :
# NON, voir https://docs.python.org/2.7/library/argparse.html
pass
#~ if len(sys.argv) == 1 :
#~ help()
#~ elif len(sys.argv) >= 2:
#~ if sys.argv[1] == "-h" or sys.argv[1] == "--help":
#~ help()
#~ elif sys.argv[1] == "-p" or sys.argv[1] == "--parsing":
#~ parse_xml()
#~ elif sys.argv[1] == "-g" or sys.argv[1] == "--generation cvs":
#~ csv()
#~ else :
#~ research = ""
#~ for i in sys.argv[1:]:
#~ research += i
#~ research += " "
#~ return 0
if __name__ == "__main__":
main() |