-
Notifications
You must be signed in to change notification settings - Fork 5
/
search_script.py
94 lines (81 loc) · 2.62 KB
/
search_script.py
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
from __future__ import division
import requests
import json
import sys
import os
from elasticsearch import Elasticsearch
from elasticsearch import exceptions
try:
# idrac_ip = os.environ['IDRAC_IP']
# idrac_username = os.environ['IDRAC_USERNAME']
# idrac_password = os.environ['IDRAC_PASSWORD']
# elastic_ip = os.environ['ELASTIC_IP']
# elastic_username = os.environ['ELASTIC_USERNAME']
# elastic_password = os.environ['ELASTIC_PASSWORD']
idrac_ip="100.98.26.49"
idrac_username="root"
idrac_password="calvin"
elastic_ip="100.98.26.172"
elastic_username="elastic"
elastic_password="changeme"
es = Elasticsearch([elastic_ip],
http_auth=(elastic_username, elastic_password),
scheme="http",
port=9200,
)
except Exception as e:
print("- FAIL: You must pass in script name along with iDRAC IP / iDRAC username / iDRAC password")
sys.exit(0)
def retrieve_logs():
index_name="lc"+idrac_ip
res=es.search(index=index_name, body={
"query":{
"range": {
"timestamp": {
"gte" : "now-5m",
"lt" : "now"
}
}
}
}
)
# print(data)
codes = {}
code_types={}
for i in res['hits']['hits']:
#print(i)
#print("\n")
for key,value in i['_source'].items():
if key=='MessageID':
code=value
code_type=value[0:3]
#print(code_type)
if code in codes:
codes[code]=codes[code]+1
else:
codes.update({code: 1})
if code_type in code_types:
code_types[code_type]=code_types[code_type]+1
else:
code_types.update({code_type: 1})
total_errors=sum(codes.values())
# print total_errors
error_percentage={}
print "\nFor Server: ",idrac_ip
# print "__________________________ \n\n\n"
print("\n\n\n")
print "Error Codes Occurrence Percentage "
print "____________________________________________ \n"
for key,value in codes.items():
error_percentage[key]= (value/total_errors)*100
print key," ",value," ",error_percentage[key],"%"
print "\n"
print "Error Types Occurrence "
print "__________________________ \n"
for key,value in code_types.items():
print key," ",value
# print(codes)
# print(code_types)
# print (total_errors)
# print error_percentage
retrieve_logs()