@@ -30,7 +30,7 @@ import (
30
30
var DEBUG bool = false
31
31
32
32
// Output debug message
33
- func dbg (v ... interface {}) {
33
+ func Dbg (v ... interface {}) {
34
34
if DEBUG {
35
35
message := ""
36
36
for _ , value := range v {
@@ -40,6 +40,16 @@ func dbg(v ...interface{}) {
40
40
}
41
41
}
42
42
43
+ // Output debug message
44
+ func Err (v ... interface {}) {
45
+ message := ""
46
+ for _ , value := range v {
47
+ message = message + " " + pyraconv .ToString (value )
48
+ }
49
+ log .Println (">>> ERROR:" , message )
50
+ }
51
+
52
+
43
53
// Prepropess file paths
44
54
// Allow absulute and relative (of pwd) paths with or wothout file:// prefix
45
55
// Return absoulute path of file
@@ -56,7 +66,7 @@ func GetFilePath(name string) string {
56
66
// for relative path will combine with current path
57
67
curDir , err := os .Getwd ()
58
68
if err != nil {
59
- dbg ("Can't determine current path" )
69
+ Dbg ("Can't determine current path" )
60
70
}
61
71
if strings .HasSuffix (strings .ToLower (curDir ), "/" ) {
62
72
filePath = curDir + filePath
@@ -85,7 +95,7 @@ func FileExists(name string) bool {
85
95
func ParseJson (jsonData string ) map [string ]interface {} {
86
96
orderedData := orderedmap .New ()
87
97
if err := json .Unmarshal ([]byte (jsonData ), & orderedData ); err != nil {
88
- dbg ("Can't parse json data:" , err )
98
+ Err ("Can't parse json data:" , err )
89
99
return nil
90
100
} else {
91
101
dt := orderedData .ToInterfaceArray ()
@@ -99,7 +109,7 @@ func LoadJsonFile(filePath string) map[string]interface{} {
99
109
if FileExists (filePath ) {
100
110
fileContent , err := ioutil .ReadFile (GetFilePath (filePath )) // just pass the file name
101
111
if err != nil {
102
- log . Println ("Can't read file: " , filePath , err )
112
+ Err ("Can't read file: " , filePath , err )
103
113
return nil
104
114
}
105
115
return ParseJson (string (fileContent ))
@@ -121,7 +131,7 @@ func loadDependencies(data map[string]interface{}) {
121
131
func loadTemplates () * template.Template {
122
132
dir , err := filepath .Abs (filepath .Dir (os .Args [0 ]))
123
133
if err != nil {
124
- dbg ("Can't determine current path" )
134
+ Dbg ("Can't determine current path" )
125
135
}
126
136
127
137
var templates * template.Template
@@ -144,7 +154,7 @@ func loadTemplates() *template.Template {
144
154
tplFuncMap ["Nobr" ] = Nobr
145
155
templates , err = template .New ("" ).Funcs (tplFuncMap ).ParseFiles (allFiles ... )
146
156
if err != nil {
147
- dbg ("Can't load templates" , err )
157
+ log . Fatal ("Can't load templates" , err )
148
158
return nil
149
159
}
150
160
@@ -156,7 +166,7 @@ func getRawData(data map[string]interface{}) {
156
166
// for every host get data
157
167
var rawData []interface {}
158
168
hosts := pyraconv .ToInterfaceMap (data ["hosts" ])
159
- dbg ("Data hosts: " , hosts )
169
+ Dbg ("Data hosts: " , hosts )
160
170
results := pyraconv .ToInterfaceMap (data ["results" ])
161
171
masterName := pyraconv .ToString (hosts ["master" ])
162
172
masterResults := pyraconv .ToInterfaceMap (results [masterName ])
@@ -199,7 +209,7 @@ func generateMdReport(checkId string, reportFilename string, reportData map[stri
199
209
_ , err := filepath .Abs (filepath .Dir (os .Args [0 ]))
200
210
f , err := os .OpenFile (outputFileName , os .O_CREATE | os .O_RDWR , 0777 )
201
211
if err != nil {
202
- dbg ("Can't create report file" , err )
212
+ Err ("Can't create report file" , err )
203
213
return false
204
214
}
205
215
defer f .Close ()
@@ -213,14 +223,14 @@ func generateMdReport(checkId string, reportFilename string, reportData map[stri
213
223
reporTpl := templates .Lookup (reportFileName )
214
224
data := reportData
215
225
if reporTpl == nil {
216
- dbg ("Template " + checkId + ".tpl not found." )
226
+ Err ("Template " + checkId + ".tpl not found." )
217
227
getRawData (data )
218
228
reportFileName = "raw.tpl"
219
229
reporTpl = templates .Lookup (reportFileName )
220
230
}
221
231
err = reporTpl .ExecuteTemplate (f , reportFileName , data )
222
232
if err != nil {
223
- dbg ("Template execute error is" , err )
233
+ Err ("Template execute error is" , err )
224
234
defer os .Remove (outputFileName )
225
235
return false
226
236
} else {
@@ -310,7 +320,7 @@ func main() {
310
320
var reportData map [string ]interface {}
311
321
objectPath , err := l .get (checkId );
312
322
if err != nil {
313
- dbg ("Cannot find and load plugin." , err )
323
+ Dbg ("Cannot find and load plugin." , err )
314
324
reportData = resultData
315
325
} else {
316
326
result , err := l .call (objectPath , resultData )
0 commit comments