1
1
#!/usr/bin/env python
2
+ from __future__ import print_function
2
3
3
4
import argparse
4
5
import sys
14
15
def retrieve_munin_configuration (settings ):
15
16
"""
16
17
"""
17
- print "Exploring Munin structure"
18
+ print ( "Exploring Munin structure" )
18
19
19
20
try :
20
21
settings = munin .discover_from_datafile (settings )
21
22
except Exception as e :
22
- print " {0} Could not process datafile ({1}), will read www and RRD cache instead" .format (Symbol .NOK_RED , settings .paths ['datafile' ])
23
+ print ( " {0} Could not process datafile ({1}), will read www and RRD cache instead" .format (Symbol .NOK_RED , settings .paths ['datafile' ]) )
23
24
24
25
# read /var/cache/munin/www to check what's currently displayed on the dashboard
25
26
settings = munin .discover_from_www (settings )
26
27
settings = rrd .discover_from_rrd (settings , insert_missing = False )
27
28
else :
28
- print " {0} Found {1}: extracted {2} measurement units" .format (Symbol .OK_GREEN , settings .paths ['datafile' ],
29
- settings .nb_fields )
29
+ print ( " {0} Found {1}: extracted {2} measurement units" .format (Symbol .OK_GREEN , settings .paths ['datafile' ],
30
+ settings .nb_fields ))
30
31
31
32
# for each host, find the /var/lib/munin/<host> directory and check if node name and plugin conf match RRD files
32
33
try :
33
34
rrd .check_rrd_files (settings )
34
35
except Exception as e :
35
- print " {0} {1}" .format (Symbol .NOK_RED , e . message )
36
+ print ( " {0} {1}" .format (Symbol .NOK_RED , e ) )
36
37
else :
37
- print " {0} Found {1} RRD files" .format (Symbol .OK_GREEN , settings .nb_rrd_files )
38
+ print ( " {0} Found {1} RRD files" .format (Symbol .OK_GREEN , settings .nb_rrd_files ) )
38
39
39
40
return settings
40
41
41
42
42
43
def main (args ):
43
- print "{0}Munin to InfluxDB migration tool{1}" .format (Color .BOLD , Color .CLEAR )
44
- print "-" * 20
44
+ print ( "{0}Munin to InfluxDB migration tool{1}" .format (Color .BOLD , Color .CLEAR ) )
45
+ print ( "-" * 20 )
45
46
46
47
settings = Settings (args )
47
48
settings = retrieve_munin_configuration (settings )
48
49
49
50
# export RRD files as XML for (much) easier parsing (but takes much more time)
50
- print "\n Exporting RRD databases:" .format (settings .nb_rrd_files )
51
+ print ( "\n Exporting RRD databases:" .format (settings .nb_rrd_files ) )
51
52
nb_xml = rrd .export_to_xml (settings )
52
- print " {0} Exported {1} RRD files to XML ({2})" .format (Symbol .OK_GREEN , nb_xml , settings .paths ['xml' ])
53
+ print ( " {0} Exported {1} RRD files to XML ({2})" .format (Symbol .OK_GREEN , nb_xml , settings .paths ['xml' ]) )
53
54
54
55
#reads every XML file and export as in the InfluxDB database
55
56
exporter = InfluxdbClient (settings )
@@ -65,17 +66,17 @@ def main(args):
65
66
exporter .import_from_xml ()
66
67
67
68
settings = exporter .get_settings ()
68
- print "{0} Munin data successfully imported to {1}/db/{2}" .format (Symbol .OK_GREEN , settings .influxdb ['host' ],
69
- settings .influxdb ['database' ])
69
+ print ( "{0} Munin data successfully imported to {1}/db/{2}" .format (Symbol .OK_GREEN , settings .influxdb ['host' ],
70
+ settings .influxdb ['database' ]))
70
71
71
72
settings .save_fetch_config ()
72
- print "{0} Configuration for 'munin-influxdb fetch' exported to {1}" .format (Symbol .OK_GREEN ,
73
- settings .paths ['fetch_config' ])
73
+ print ( "{0} Configuration for 'munin-influxdb fetch' exported to {1}" .format (Symbol .OK_GREEN ,
74
+ settings .paths ['fetch_config' ]))
74
75
75
76
# Generate a JSON file to be uploaded to Grafana
76
- print "\n {0}Grafaba dashboard{1}" .format (Color .BOLD , Color .CLEAR )
77
+ print ( "\n {0}Grafaba dashboard{1}" .format (Color .BOLD , Color .CLEAR ) )
77
78
if not settings .influxdb ['group_fields' ] and settings .grafana ['create' ]:
78
- print Symbol . NOK_RED , " Grafana dashboard generation is only supported in grouped fields mode."
79
+ print ( "%s Grafana dashboard generation is only supported in grouped fields mode.", Symbol . NOK_RED )
79
80
return
80
81
81
82
if settings .interactive :
@@ -92,19 +93,19 @@ def main(args):
92
93
try :
93
94
dash_url = dashboard .upload ()
94
95
except Exception as e :
95
- print "{0} Didn't quite work uploading: {1}" .format (Symbol .NOK_RED , e . message )
96
+ print ( "{0} Didn't quite work uploading: {1}" .format (Symbol .NOK_RED , e ) )
96
97
else :
97
- print "{0} A Grafana dashboard has been successfully uploaded to {1}" .format (Symbol .OK_GREEN , dash_url )
98
+ print ( "{0} A Grafana dashboard has been successfully uploaded to {1}" .format (Symbol .OK_GREEN , dash_url ) )
98
99
99
100
if settings .grafana ['filename' ]:
100
101
try :
101
102
dashboard .save ()
102
103
except Exception as e :
103
- print "{0} Could not write Grafana dashboard: {1}" .format (Symbol .NOK_RED , e . message )
104
+ print ( "{0} Could not write Grafana dashboard: {1}" .format (Symbol .NOK_RED , e ) )
104
105
else :
105
- print "{0} A Grafana dashboard has been successfully generated to {1}" .format (Symbol .OK_GREEN , settings .grafana ['filename' ])
106
+ print ( "{0} A Grafana dashboard has been successfully generated to {1}" .format (Symbol .OK_GREEN , settings .grafana ['filename' ]) )
106
107
else :
107
- print "Then we're good! Have a nice day!"
108
+ print ( "Then we're good! Have a nice day!" )
108
109
109
110
110
111
if __name__ == "__main__" :
@@ -172,8 +173,8 @@ def main(args):
172
173
try :
173
174
main (args )
174
175
except KeyboardInterrupt :
175
- print "\n {0} Canceled." .format (Symbol .NOK_RED )
176
+ print ( "\n {0} Canceled." .format (Symbol .NOK_RED ) )
176
177
sys .exit (1 )
177
178
except Exception as e :
178
- print "{0} Error: {1}" .format (Symbol .NOK_RED , e . message )
179
- sys .exit (1 )
179
+ print ( "{0} Error: {1}" .format (Symbol .NOK_RED , e ) )
180
+ sys .exit (1 )
0 commit comments