-
Notifications
You must be signed in to change notification settings - Fork 7
/
sysinv.cpp
227 lines (177 loc) · 5.29 KB
/
sysinv.cpp
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include "stdafx.h"
#include "sysinv.h"
#include "argparser.h"
#include "version.h"
#include "smbios.h"
#define OUT_LIST 0x1
#define OUT_XML 0x2
#define OUT_JSON 0x3
#define OUT_WALK 0x4
#define OUT_YAML 0x5
int HotFixTest();
void print_usage(int ret);
int main(int argc, CHAR* argv[])
{
FILE *out = stdout;
PNODE root, agent, software, hardware, configuration, storage, network, node;
DWORD format = OUT_YAML;
DWORD i = 0;
PARGLIST argList = parse_args(argc, argv);
PARG arg;
BOOL getSoftware = 1;
BOOL getHardware = 1;
BOOL getConfiguration = 1;
for(i = 0; i < argList->count; i++) {
arg = &argList->args[i];
// Parse help request
if(0 == strcmp("/?", arg->arg) || 0 == strcmp("-?", arg->arg)
|| 0 == stricmp("/h", arg->arg) || 0 == strcmp("-h", arg->arg)
|| 0 == strcmp("--help", arg->arg)) {
print_usage(0);
}
// Parse file output argument
else if(0 == stricmp("/f", arg->arg) || 0 == strcmp("-f", arg->arg)) {
if(NULL == arg->val) {
fprintf(stderr, "File name not specified.\n");
exit(1);
}
if(NULL == (out = fopen(arg->val, "w"))) {
fprintf(stderr, "Unable to open '%s' for writing.\n", arg->val);
exit(1);
}
}
// Parse output arguments
else if(0 == stricmp("/o", arg->arg) || 0 == strcmp("-o", arg->arg)) {
if(NULL == arg->val) {
fprintf(stderr, "Output format not specified.\n");
exit(1);
}
if(0 == stricmp("xml", arg->val))
format = OUT_XML;
else if(0 == stricmp("json", arg->val))
format = OUT_JSON;
else if (0 == stricmp("walk", arg->val))
format = OUT_WALK;
else if (0 == stricmp("tree", arg->val))
format = OUT_LIST;
else if (0 == stricmp("yaml", arg->val))
format = OUT_YAML;
else {
fprintf(stderr, "Unknown output type: '%s'\n", arg->val);
exit(1);
}
}
}
free(argList);
// Configure error handling to prevent dialog boxes
SetErrorMode(SEM_FAILCRITICALERRORS);
// Build info nodes
root = GetSystemDetail();
// Get agent info
agent = GetAgentDetail();
node_append_child(root, agent);
if (getHardware) {
hardware = node_append_new(root, L"Hardware", NFLG_PLACEHOLDER);
// Virtualization info
node = GetVirtualizationDetail();
node_append_child(hardware, node);
// SMBIOS info
node = GetSmbiosDetail();
node_append_child(hardware, node);
// OEM String
node = EnumOemStrings();
node_append_child(hardware, node);
// BIOS Info
node = GetBiosDetail();
node_append_child(hardware, node);
// System Chassis
node = EnumChassis();
node_append_child(hardware, node);
// Baseboards
node = EnumBaseboards();
node_append_child(hardware, node);
// Memory
node = EnumMemorySockets();
node_append_child(hardware, node);
// Processor Sockets
node = EnumProcSockets();
node_append_child(hardware, node);
// Get CPU info
node = EnumProcessors();
node_append_child(hardware, node);
// Get disks
node = EnumDisks();
node_append_child(hardware, node);
}
if (getSoftware) {
software = node_append_new(root, L"Software", NFLG_PLACEHOLDER);
// Get OS info
node = GetOperatingSystemDetail();
node_append_child(software, node);
// Get Software packages
node = EnumPackages();
node_append_child(software, node);
// Get hotfixes QFE
node_append_child(software, EnumHotfixes());
}
if (getConfiguration) {
configuration = node_append_new(root, L"Configuration", NFLG_PLACEHOLDER);
storage = node_append_new(configuration, L"Storage", NFLG_PLACEHOLDER);
network = node_append_new(configuration, L"Network", NFLG_PLACEHOLDER);
// Get volume info
node = EnumVolumes();
node_append_child(storage, node);
// Get network configuration
node_append_child(network, EnumNetworkInterfaces());
// Get network routes
node_append_child(network, EnumNetworkRoutes());
// Get Failover Cluster Node
node = EnumClusterServices();
if (NULL != node)
node_append_child(configuration, node);
}
// Release residual handles
ReleaseSmbiosData();
// Add errors
node = EnumErrorLog();
if (NULL != node)
node_append_child(root, node);
// Print
switch(format) {
case OUT_XML:
node_to_xml(root, out, 0);
break;
case OUT_JSON:
node_to_json(root, out, 0);
break;
case OUT_WALK:
node_to_walk(root, out, 0);
break;
case OUT_LIST:
node_to_list(root, out, 0);
break;
case OUT_YAML:
node_to_yaml(root, out, 0);
break;
}
fclose(out);
node_free(root, true);
return 0;
}
void print_usage(int ret)
{
printf("%s v%s\n%s %s\n\n%s\n\n",
VER_PRODUCTNAME_STR, VER_PRODUCT_VERSION_STR,
VER_COPYRIGHT_STR, VER_PRODUCT_COMPANY,
VER_FILE_DESCRIPTION_STR);
printf("%s [/F:filename] [/O:format]\n\n", VER_ORIGINAL_FILENAME_STR);
printf(" /F Write to file instead of printing to screen\n");
printf(" /O Change output format\n");
printf(" YAML Output data as YAML document\n");
printf(" TREE Output data as tree list\n");
printf(" XML Output data as XML tree\n");
printf(" JSON Output data as Javascript object\n");
printf(" WALK Output data as snmp-walk style list\n");
printf("\n");
exit(ret);
}