@@ -57,44 +57,41 @@ def quit_handler(_signo=None, _stack_frame=None):
57
57
version_args = args .pg_version .split ('_' )
58
58
define_pg_version (version_args )
59
59
cfg = Config (args .config_file , args .plugins_dirs )
60
- if not len (commands ) == 3 :
60
+ if not len (commands ) == 2 and not len ( commands ) == 3 :
61
61
print_total_help ()
62
62
if commands [1 ] == 'zabbix-parameters' :
63
63
# zabbix agent keys generation
64
64
Plugin .Type = 'agent' # change plugin type for template generator
65
65
plugins = []
66
+ if len (commands ) == 2 :
67
+ commands .append ('postgrespro_agent.conf' )
68
+ print ('Configuration file for zabbix-agent have been saved in postgrespro_agent.conf file' )
66
69
for klass in Plugin .only_child_subclasses ():
67
70
if klass .__name__ == "PgWaitSampling" : # check if plugin is for EE
68
71
if Plugin .VersionPG ['type' ] == 'PGEE' :
69
72
plugins .append (klass (cfg ))
70
-
71
73
else :
72
74
if klass .__name__ != "Cfs" :
73
75
plugins .append (klass (cfg ))
74
- types = args .plugin_type .split (',' )
75
- # check if any plugin types is equal
76
- if len (types ) > 1 :
77
- if is_any_equal (types ):
78
- print_total_help ()
79
- # if number of plugin types is more than 1 => plugin type should be 'all'
80
- if len (types ) > 1 :
81
- args .plugin_type = 'all'
76
+ args .plugin_type = correct_plugin_type (args .plugin_type )
82
77
if args .plugin_type == 'pg' or args .plugin_type == 'sys' or args .plugin_type == 'all' :
83
78
# check if conf file has a path
84
79
len_path = commands [2 ].rfind ("/" )
85
80
# get path for conf file and scripts
86
81
if len_path != - 1 :
87
- path = commands [2 ][:len_path ] + "/scripts"
88
- Plugin .PATH = path
82
+ path = commands [2 ][:len_path ] + "/scripts"
83
+ Plugin .PATH = path
89
84
else :
90
85
path = os .getcwd () + "/scripts"
91
86
Plugin .PATH = path
92
- print (path )
93
87
# create directory for scripts along the path of conf file if needed
94
88
if not os .path .exists (path ):
95
89
os .makedirs (path )
96
90
print ("directory for scripts has created" )
97
91
template = GetKeys ()
92
+ # if no name for zabbix-parameters save to postgrespro.conf
93
+ if commands [2 ].rfind ("/" ) == len (commands [2 ]) - 1 :
94
+ commands [2 ] = commands [2 ][:- 1 ] + "/postgrespro.conf"
98
95
# write conf file
99
96
with codecs .open (commands [2 ], 'w' , 'utf-8' ) as f :
100
97
f .write (template .txt (args .plugin_type , plugins )) # pass command type
@@ -106,36 +103,42 @@ def quit_handler(_signo=None, _stack_frame=None):
106
103
os .chmod (path + "/" + key + ".sh" , 0o755 )
107
104
print ("Bash scripts for native zabbix-agent have been saved to {0}" .format (path ))
108
105
else :
106
+ print ("Got wrong plugin types. For help, see the message below" )
109
107
print_total_help ()
110
108
sys .exit (0 )
111
109
elif commands [1 ] == 'config' :
110
+ if len (commands ) == 2 :
111
+ commands .append ('postgrespro.conf' )
112
+ print ('Configuration file for mamonsu have been saved in postgrespro.conf file' )
112
113
with open (commands [2 ], 'w' ) as fd :
113
114
cfg .config .write (fd )
114
115
sys .exit (0 )
115
116
elif commands [1 ] == 'template' :
116
117
plugins = []
118
+ if len (commands ) == 2 :
119
+ commands .append ('postgrespro.xml' )
120
+ print ('Template for mamonsu have been saved in postgrespro.conf file' )
117
121
for klass in Plugin .only_child_subclasses ():
118
122
if klass .__name__ == "PgWaitSampling" : # check if plugin is for EE
119
123
if Plugin .VersionPG ['type' ] == 'PGEE' :
120
124
plugins .append (klass (cfg ))
121
125
else :
122
126
plugins .append (klass (cfg ))
123
127
template = ZbxTemplate (args .template , args .application )
128
+ # if no name for template save to postgrespro.xml
129
+ if commands [2 ].rfind ("/" ) == len (commands [2 ]) - 1 :
130
+ commands [2 ] = commands [2 ][:- 1 ] + "/postgrespro.xml"
124
131
with codecs .open (commands [2 ], 'w' , 'utf-8' ) as f :
125
132
# template for mamonsu (zabbix-trapper) is generated for all available plugins
126
133
f .write (template .xml ("all" , plugins )) # set type to 'all' for mamonsu
127
134
sys .exit (0 )
128
135
elif commands [1 ] == 'zabbix-template' :
129
136
Plugin .Type = 'agent' # change plugin type for template generator
137
+ if len (commands ) == 2 :
138
+ commands .append ('postgrespro_agent.xml' )
139
+ print ('Template for zabbix-agent have been saved in postgrespro_agent.xml file' )
130
140
plugins = []
131
- types = args .plugin_type .split (',' )
132
- # check if any plugin types is equal
133
- if len (types ) > 1 :
134
- if is_any_equal (types ):
135
- print_total_help ()
136
- # if number of plugin types is more than 1 => plugin type should be 'all'
137
- if len (types ) > 1 :
138
- args .plugin_type = 'all'
141
+ args .plugin_type = correct_plugin_type (args .plugin_type )
139
142
if args .plugin_type == 'pg' or args .plugin_type == 'sys' or args .plugin_type == 'all' :
140
143
for klass in Plugin .only_child_subclasses ():
141
144
if klass .__name__ == "PgWaitSampling" : # check if plugin is for EE
@@ -145,11 +148,15 @@ def quit_handler(_signo=None, _stack_frame=None):
145
148
if klass .__name__ != "Cfs" :
146
149
plugins .append (klass (cfg ))
147
150
template = ZbxTemplate (args .template , args .application )
151
+ # if no name for template save to postgrespro.xml
152
+ if commands [2 ].rfind ("/" ) == len (commands [2 ]) - 1 :
153
+ commands [2 ] = commands [2 ][:- 1 ] + "/postgrespro.xml"
148
154
with codecs .open (commands [2 ], 'w' , 'utf-8' ) as f :
149
155
# template for zabbix-agent is generated for selected plugin-type
150
156
f .write (template .xml (args .plugin_type , plugins ))
151
157
sys .exit (0 )
152
158
else :
159
+ print ("Got wrong plugin types. For help, see the message below" )
153
160
print_total_help ()
154
161
else :
155
162
print_total_help ()
@@ -200,25 +207,58 @@ def define_pg_version(version_args):
200
207
LooseVersion (version_args [0 ]) == "9.6" or LooseVersion (version_args [0 ]) == "9.5" :
201
208
version_number = version_args [0 ].split ('.' )
202
209
if len (version_number ) > 3 :
210
+ print ("Version number is too long. For help, see the message below" )
203
211
print_total_help ()
204
212
else :
205
213
for num in version_number :
206
214
if not num .isdigit ():
215
+ print ("Version number contains only digits. For help, see the message below" )
207
216
print_total_help ()
208
217
Plugin .VersionPG ['number' ] = version_args [0 ]
209
218
else :
219
+ print ("Version number is not valid. For help, see the message below" )
210
220
print_total_help ()
211
221
elif len (version_args ) == 2 and (version_args [0 ] == "PGEE" or version_args [0 ] == "PGPRO" ):
212
222
version_number = version_args [1 ].split ('.' )
213
223
if len (version_number ) > 3 :
224
+ print ("Version number is too long. For help, see the message below" )
214
225
print_total_help ()
215
226
else :
216
227
for num in version_number [1 :]:
217
228
if not num .isdigit ():
229
+ print ("Version number contains only digits. For help, see the message below" )
218
230
print_total_help ()
219
231
if version_args [1 ] == "11" or LooseVersion (version_args [1 ]) == "10" or \
220
232
LooseVersion (version_args [1 ]) == "9.6" or LooseVersion (version_args [1 ]) == "9.5" :
221
233
Plugin .VersionPG ['number' ] = version_args [1 ]
222
234
Plugin .VersionPG ['type' ] = version_args [0 ]
223
235
else :
236
+ print ("Version number is not valid. For help, see the message below" )
224
237
print_total_help ()
238
+ else :
239
+ print ("Version number is not valid. For help, see the message below" )
240
+ print_total_help ()
241
+
242
+
243
+ # check if plugin type is valid
244
+ def correct_plugin_type (plugin_type ):
245
+ types = plugin_type .split (',' )
246
+ # if number of plugin types is more than 1 and plugin types are valid => plugin type should be 'all'
247
+ valid_plugin_types = ('pg' , 'sys' , 'all' )
248
+ if len (types ) == 2 or len (types ) == 3 :
249
+ # check if any plugin types is equal
250
+ if is_any_equal (types ):
251
+ print ("Got equal plugin types. For help, see the message below" )
252
+ print_total_help ()
253
+ # if plugin type name is wrong
254
+ if False in [type in valid_plugin_types for type in types ]:
255
+ print ("Got wrong plugin types. For help, see the message below" )
256
+ print_total_help ()
257
+ else :
258
+ plugin_type = 'all'
259
+ return plugin_type
260
+ elif len (types ) > 3 :
261
+ print ("Got more than 3 plugin types. For help, see the message below" )
262
+ print_total_help ()
263
+ else :
264
+ return plugin_type
0 commit comments