-
Notifications
You must be signed in to change notification settings - Fork 5
/
docker_lc_exporter.py
139 lines (101 loc) · 3.75 KB
/
docker_lc_exporter.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
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
import requests
import json
import sys
import re
import time
import os
import warnings
from elasticsearch import Elasticsearch
from datetime import datetime
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']
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 getSystemName():
response = requests.get('https://%s/redfish/v1/Systems/System.Embedded.1/Bios' % idrac_ip, verify=False,
auth=(idrac_username, idrac_password))
data = response.json()
system_name = data[u'Attributes']['SystemModelName']
return (system_name)
# Function to get lifecycle logs (LC)
def getJSONResponse(next_url):
response = requests.get('https://%s%s' % (idrac_ip, next_url), verify=False, auth=(idrac_username, idrac_password))
data = response.json()
return data
def get_LC_logs():
try:
es.indices.delete(index='lc_index', doc_type='lc_doc'+str(idrac_ip))
except Exception as e:
pass
columns = [
'Idrac_Ip',
'Server_Model',
'Created',
'Description',
'EntryType',
'Id',
'Message',
'MessageID',
'Name',
'OemRecordFormat',
'Severity']
system_name = getSystemName()
print(system_name)
data = getJSONResponse('/redfish/v1/Managers/iDRAC.Embedded.1/Logs/Lclog')
try:
while (data[u'@odata.nextLink'] != None):
time.sleep(2)
print(data[u'@odata.nextLink'])
for i in data[u'Members']:
print("%s : %s" % ('Id', i[u'Id']))
data_dict = {
'Idrac_Ip': idrac_ip,
'Server_Model': system_name,
'Created': i[u'Created'],
'Description': i[u'Description'],
'EntryType': i[u'EntryType'],
'Id': i[u'Id'],
'Message': i[u'Message'],
'MessageID': i[u'MessageID'],
'Name': i[u'Name'],
'OemRecordFormat': i[u'OemRecordFormat'],
'Severity': i[u'Severity'],
}
# df.loc[len(df)] = data_dict
es.create(index='lc_index', doc_type='lc_doc'+str(idrac_ip), id=str(i[u'Id']), body=data_dict)
print("#" * 100)
time.sleep(2)
data = getJSONResponse(data[u'@odata.nextLink'])
except KeyError as e:
print("Error:", e)
print(dir(e))
for i in data[u'Members']:
data_dict = {
'Idrac_Ip': str(idrac_ip),
'Server_Model': system_name,
'Created': i[u'Created'],
'Description': i[u'Description'],
'EntryType': i[u'EntryType'],
'Id': i[u'Id'],
'Message': i[u'Message'],
'MessageID': i[u'MessageID'],
'Name': i[u'Name'],
'OemRecordFormat': i[u'OemRecordFormat'],
'Severity': i[u'Severity'],
}
# df.loc[len(df)] = data_dict
es.create(index='lc_index', doc_type='lc_doc'+str(idrac_ip), id=str(i[u'Id']), body=data_dict)
print("%s : %s" % ('Id', i[u'Id']))
return
get_LC_logs()