@@ -25,12 +25,7 @@ def quit_handler(_signo=None, _stack_frame=None):
25
25
signal .signal (signal .SIGTERM , quit_handler )
26
26
if platform .LINUX :
27
27
signal .signal (signal .SIGQUIT , quit_handler )
28
- # temporal list to keep names of all refactored classes
29
- #refactored_classes = ["Oldest", "PgBufferCache", "ArchiveCommand", "BgWriter", "Checkpoint", "Connections",
30
- # "Databases", "PgHealth", "Instance", "PgLocks", "Xlog",
31
- # "PgStatProgressVacuum", "PgStatStatement", "PgWaitSampling", "La", "OpenFiles",
32
- # "SystemUptime", "ProcStat", "Net", "Memory", "DiskStats", "DiskSizes", "DefConfTest",
33
- # "Health"]
28
+
34
29
commands = sys .argv [1 :]
35
30
if len (commands ) > 0 :
36
31
tool = commands [0 ]
@@ -61,10 +56,6 @@ def quit_handler(_signo=None, _stack_frame=None):
61
56
# get PG version
62
57
version_args = args .pg_version .split ('_' )
63
58
define_pg_version (version_args )
64
- # print(Plugin.VersionPG['type'])
65
- # print(Plugin.VersionPG['number'])
66
- # print("this is args", args)
67
- # print("this is commands", commands)
68
59
cfg = Config (args .config_file , args .plugins_dirs )
69
60
if not len (commands ) == 3 :
70
61
print_total_help ()
@@ -91,8 +82,6 @@ def quit_handler(_signo=None, _stack_frame=None):
91
82
if args .plugin_type == 'pg' or args .plugin_type == 'sys' or args .plugin_type == 'all' :
92
83
# check if conf file has a path
93
84
len_path = commands [2 ].rfind ("/" )
94
- # print(len_path)
95
- # print(len(commands[2]))
96
85
# get path for conf file and scripts
97
86
if len_path != - 1 :
98
87
path = commands [2 ][:len_path ] + "/scripts"
@@ -112,9 +101,10 @@ def quit_handler(_signo=None, _stack_frame=None):
112
101
# write bash scripts for zabbix - agent to a file
113
102
for key in Scripts .Bash :
114
103
with codecs .open (path + "/" + key + ".sh" , 'w+' , 'utf-8' ) as f :
104
+ # configuration file for zabbix-agent is generated for selected plugin-type
115
105
f .write (Scripts .Bash [key ]) # pass script itself
116
106
os .chmod (path + "/" + key + ".sh" , 0o755 )
117
- print ("Bash scripts for native zabbix agent have been saved to {0}" .format (path ))
107
+ print ("Bash scripts for native zabbix- agent have been saved to {0}" .format (path ))
118
108
else :
119
109
print_total_help ()
120
110
sys .exit (0 )
@@ -132,22 +122,35 @@ def quit_handler(_signo=None, _stack_frame=None):
132
122
plugins .append (klass (cfg ))
133
123
template = ZbxTemplate (args .template , args .application )
134
124
with codecs .open (commands [2 ], 'w' , 'utf-8' ) as f :
135
- f .write (template .xml (plugins ))
125
+ # template for mamonsu (zabbix-trapper) is generated for all available plugins
126
+ f .write (template .xml ("all" , plugins )) # set type to 'all' for mamonsu
136
127
sys .exit (0 )
137
128
elif commands [1 ] == 'zabbix-template' :
138
129
Plugin .Type = 'agent' # change plugin type for template generator
139
130
plugins = []
140
- for klass in Plugin .only_child_subclasses ():
141
- if klass .__name__ == "PgWaitSampling" : # check if plugin is for EE
142
- if Plugin .VersionPG ['type' ] == 'PGEE' :
143
- plugins .append (klass (cfg ))
144
- else :
145
- if klass .__name__ != "Cfs" :
146
- plugins .append (klass (cfg ))
147
- template = ZbxTemplate (args .template , args .application )
148
- with codecs .open (commands [2 ], 'w' , 'utf-8' ) as f :
149
- f .write (template .xml (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'
139
+ if args .plugin_type == 'pg' or args .plugin_type == 'sys' or args .plugin_type == 'all' :
140
+ for klass in Plugin .only_child_subclasses ():
141
+ if klass .__name__ == "PgWaitSampling" : # check if plugin is for EE
142
+ if Plugin .VersionPG ['type' ] == 'PGEE' :
143
+ plugins .append (klass (cfg ))
144
+ else :
145
+ if klass .__name__ != "Cfs" :
146
+ plugins .append (klass (cfg ))
147
+ template = ZbxTemplate (args .template , args .application )
148
+ with codecs .open (commands [2 ], 'w' , 'utf-8' ) as f :
149
+ # template for zabbix-agent is generated for selected plugin-type
150
+ f .write (template .xml (args .plugin_type , plugins ))
150
151
sys .exit (0 )
152
+ else :
153
+ print_total_help ()
151
154
else :
152
155
print_total_help ()
153
156
0 commit comments