-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogparser.groovy
More file actions
298 lines (247 loc) · 8.32 KB
/
logparser.groovy
File metadata and controls
298 lines (247 loc) · 8.32 KB
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*
#############################################################
# HPC Log Parser
# This App allows you to parse the logs found in HPC.
# 04/12/2014
#############################################################
*/
import com.liquidlabs.common.LifeCycle;
import com.liquidlabs.common.*
println("Starting")
Properties properties = new Properties()
def props = args.length > 0 ? ".\\lib\\" + args[0] : ".\\lib\\parser.properties"
def propertiesFile = new File(props)
if (propertiesFile.exists()){
propertiesFile.withInputStream{
properties.load(it)
}
}
else
{
println "No Properties File Present"
println System.getProperty("user.dir")
return 0
}
def getInput(defaultValue){
value = new InputStreamReader(System.in).readLine()
if (value == ""){
if (defaultValue !="")
value = defaultValue
else{
print("Input Required\n")
return getInput(defaultValue)
}
}
return value
}
println (props)
String mode = properties.runMode
//Setting defaults (used in both modes)
String ch2Def = properties.defaultLevel
String ch1Def = properties.choiceMethod
File source = new File(properties.sourcePath)
File destination = new File(properties.destinationPath)
String logDays = properties.days
def level = ch2Def
def method = ch1Def
def filelist = []
def today = new Date()
def storage = properties.storage
//Manual Mode
if (mode=="1"){
println "\nWelcome to the Microsoft HPC Server Log Parser"
println "------------------------------------\n"
println "This is set to Manual Mode - if you wish to run this as an automated script, please edit the parser.properties file and set the default settings you require"
println "\nWould you like to parse all the available logs of a certain type or just a selection?"
println " 1. All logs of a certain type"
println " 2. A selection by type and date"
println "\nPlease select a choice {1 or 2} and press enter.\n"
method = getInput(ch1Def)
println " You have selected $method\n\n"
println " Please choose a Level\n"
println" 1. Error and Critical only"
println" 2. Warning, Error, and Critical only"
println" 3. Info, Warning, Error and Critical only"
println" 4. All: Verbose, Info, Warning, Error, and Critical"
println" \nPlease select a choice {1-4} and press enter.\n"
level = getInput(ch2Def)
println " You have selected $level\n"
if (!source.exists()){
println "The pre-configured source for the Logs is set to $source"
println "This directory does not exist. Please edit the parser.properties and try again.\n"
println "Goodbye!\n"
System.exit(1)
}
else{
println "The pre-configured source for the Logs is set to $source"
println "If you have another directory you wish to use, edit the parser.properties.\n\n"
}
if (!destination.exists()){
println "The pre-configured destination for the Logs is set to $destination"
println "This directory does not exist, it will be created for you."
println "If you wish to change the directory, type N (case sensitive) to quit, then edit the properties file."
println "If you are happy to have the directory created, press enter\n\n"
def createit = getInput("Y")
if (createit == "N"){
println "Goodbye!"
System.exit(1)
}
else{
destination.mkdir()
println "Destination file created"
}
}
else{
println "The pre-configured source for the Logs is set to $destination"
println "If you have another directory you wish to use, edit the parser.properties.\n\n"
}
if (method=="1"){
def providers = ["1":"mgmt","2":"sche","3":"sdm","4":"diag","5":"rept","6":"nmgr","7":"msvrmbrok","8":"mclt","9":"brok","10":"sdgm","11":"sess"]
println"\n You have selected all logs of a certain type. Please select the type of Logs that you are interested in [1-11]."
println" ----------------------------------"
println" 1. HPC Management Service"
println" 2. HPC Job Scheduler Service"
println" 3. HPC SDM Store Service"
println" 4. HPC Diagnostics Service"
println" 5. HPC Reporting Service"
println" 6. HPC Node Manager Service"
println" 7. HPC Monitoring Server Service"
println" 8. HPC Monitoring Client Service"
println" 9. HPC Broker Service"
println" 10. HPC SOA Diag Mon Service"
println" 11. HPC Session Service"
println" ----------------------------------"
println" If you want ALL of them, do so by date"
def selectP = getInput("")
selection = providers[selectP]
if (selection==null){
println "You have selected an invalid type."
System.exit(2)
}
println" \nYou have selected $selectP"
}
if (method=="2"){
def fileTypes = ["1":"Management","2":"Scheduler","3":"Sdm","4":"Diagnostics","5":"NodeManager","6":"MonitoringServer","7":"MonitoringClient","8":"Broker","9":"SoaDiagMon","10":"Session","11":".bin"]
println"\nYou have chosen to parse logs by their date."
println" Please select the Logs that you are interested in"
println" ----------------------------------"
println" 1. HPC Management Service"
println" 2. HPC Job Scheduler Service"
println" 3. HPC SDM Store Service"
println" 4. HPC Diagnostics Service"
println" 5. HPC Node Manager Service"
println" 6. HPC Monitoring Server Service"
println" 7. HPC Monitoring Client Service"
println" 8. HPC Broker Service"
println" 9. HPC SOA Diag Mon Service"
println" 10. HPC Session Service"
println" 11. ALL OF THEM - This could take a while"
println" ----------------------------------"
def selectP = getInput("")
selection = fileTypes[selectP]
if (selection==null){
println "You have selected an invalid type."
System.exit(2)
}
println" \nYou have selected $selectP"
println"Please enter the number of days logging you would like"
daysLogged = getInput(logDays)
println"\n You have selected $daysLogged"
def maxAge = today - daysLogged.toInteger()
source.eachFileRecurse {file ->
if(file.path.contains(selection)){
def currentAge = new Date(file.lastModified())
//println currentAge
if(currentAge > maxAge){
filelist << file
}
}
}
}
println"How would you like to store this data?"
println" 0. Short Term (One set of files)"
println" This will wipe all previous extracts to $destination"
println" 1. Once a Day. A sub-folder will be created for today."
println" 2. Every Run. A new folder will be created every time you run this."
println" -----------------------------------------------------------------------"
storage = getInput(storage)
println" You have selected $storage"
}
if(mode=="0"){
if(!source.exists()){
println "$source does not exist. Please edit the properties file"
System.exit(1)
}
if(!destination.exists()){
destination.mkdir()
}
if(method=="1"){
selection = properties.select1
println("Running all of Type $selection")
}
if(method=="2"){
selection = properties.select2
source.eachFileRecurse {file ->
if(file.path.contains(selection)){
def maxAge = today - logDays.toInteger()
def currentAge = new Date(file.lastModified())
//println currentAge
if(currentAge > maxAge){
filelist << file
println(filelist)
}
}
}
}
}
//Storage Policy - 1, multiple or wipe clean
def fname
if (storage=="1"){
fname = today.format('yyMMMdd')
destination.eachFile(){ file ->
if(file.name.contains(fname))
println "This has already run today."
System.exit(3)
}
}
if (storage=="2"){
fname = today.format('yyMMMddHHmmss')
}
if (storage=="0"){
fname = ""
destination.eachFile{file ->
if(file.name.contains(".log")){
file.delete()
}
}
}
File newDest = new File(destination.toString() + "\\" + fname)
destination = newDest
if (!destination.exists()){
destination.mkdir()
println(destination)
}
//Running the commands with set parameters
def command
if(method=="1"){
command = """ cmd /C hpctrace getlog $selection $level -d:$destination"""
println command
def proc = command.execute()
proc.waitFor()
println "return code: ${ proc.exitValue()}"
println "stderr: ${proc.err.text}"
println "stdout: ${proc.in.text}"
}
if(method=="2"){
filelist.each(){ file ->
command = """cmd /C hpctrace parselog \"$file\" $level -d:$destination"""
println command
def proc = command.execute()
proc.waitFor()
println "return code: ${ proc.exitValue()}"
println "stderr: ${proc.err.text}"
println "stdout: ${proc.in.text}"
}
}
println("Exiting")
System.exit(0)