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
|
#!/usr/bin/env python3
"""
Copyright (C) 2010-2013 by Cloud Computing Center for Mobile Applications
Industrial Technology Research Institute
File Name
ipmi_sel_entries
1. Use ipmitool to collect event log information
2. Calculate entries number of system event log
3. Criteria: the A log must be capable of saving at least 256 entries
Description
Use ipmitool to get system event log info and calculate whether
total number of entries is more than 256.
Authors
Sophia Wu <Sophia.Wu@itri.org.tw>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3,
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import sys
import time
import shlex
import re
import subprocess
from subprocess import (
CalledProcessError,
check_call,
check_output
)
from argparse import (
ArgumentParser,
RawTextHelpFormatter
)
import configparser
#Retrieve entries number that already used
def get_entry_used(output):
entry_used = re.search(r'Entries\D*([0-9 ]+)', output)
return entry_used.group(1).strip()
#Retrieve free entries that available
def get_entry_free(output):
entry_free = re.search(r'# Free Units\D*([0-9 ]+)', output)
return entry_free.group(1).strip()
#Use ipmitool to retrieve sel information
def get_sel_info(host_ip, user, password):
cmd = 'ipmitool -H {} -U {} -P {} sel'.format(host_ip, user, password)
ipmi_sel_return = check_output(shlex.split(cmd), universal_newlines=True)
return ipmi_sel_return
def sel_entry_test(args):
#Default config file to config requirement info for DCMI in-band/out-of-band access
DEFAULT_CFG = "/etc/checkbox.d/me.cfg"
if not "config" in vars(args):
config_file = DEFAULT_CFG
else:
config_file = args.config
config = configparser.RawConfigParser()
try:
config.readfp(open(config_file))
except IOError:
print("No config file found")
return 10
# Acquire ME IP/Credential parameters from config file
try:
targets_options = config.options('Targets')
targets_list = []
for target_key in targets_options:
targets_list.append(config.get('Targets', target_key))
if not targets_list:
print("Invalid or Empty targets")
return 20
except configparser.Error:
print("Invalid or Empty targets")
return 30
try:
user_value = config.get('Account', 'USER')
passwd_value = config.get('Account', 'PASSWORD')
except configparser.Error:
print("Invalid or Empty credential info")
return 40
for target in targets_list:
if not target or not user_value or not passwd_value:
print("Require Taget IP, Account(USER/PASSWORD) for DCMI out-of-band access")
return 50
else:
print("SUT =", target)
try:
sel_return = get_sel_info(target, user_value, passwd_value)
time.sleep(5)
except CalledProcessError as command_exception:
print("Failed executing ipmi command, Reason: %s." %(command_exception))
return 60
try:
print("Used Entry:", int(get_entry_used(sel_return)))
print("Free Entry:", int(get_entry_free(sel_return)))
except:
print("Error to parse SEL info")
return 70
try:
entry_space = int(get_entry_used(sel_return))+int(get_entry_free(sel_return))
except ArithmeticError:
print("Arithmetic Error")
return 80
if entry_space < 256:
print("Entries Number:", int(entry_space), "Entries Number is less than 256")
return 90
else:
print("Entries Number of SUT is more than 256.")
return 0
def main():
intro_message = "Default config location is /etc/checkbox.d/me.cfg"
parser = ArgumentParser(description=intro_message,
formatter_class=RawTextHelpFormatter)
parser.add_argument('--config', default="/etc/checkbox.d/me.cfg",
help="Supply config file for getting default credential")
args = parser.parse_args()
return sel_entry_test(args)
if __name__ == "__main__":
sys.exit(main())
|