14
14
from mamonsu .lib .zbx_template import ZbxTemplate
15
15
from mamonsu .lib .get_keys import GetKeys
16
16
from distutils .version import LooseVersion
17
+ from mamonsu .plugins .system .linux .scripts import Scripts
17
18
18
19
19
20
def start ():
@@ -28,7 +29,8 @@ def quit_handler(_signo=None, _stack_frame=None):
28
29
refactored_classes = ["Oldest" , "PgBufferCache" , "ArchiveCommand" , "BgWriter" , "Checkpoint" , "Connections" ,
29
30
"Databases" , "PgHealth" , "Instance" , "PgLocks" , "Xlog" ,
30
31
"PgStatProgressVacuum" , "PgStatStatement" , "PgWaitSampling" , "La" , "OpenFiles" ,
31
- "SystemUptime" , "ProcStat" , "Net" , "Memory" , "DiskStats" , "DiskSizes" ]
32
+ "SystemUptime" , "ProcStat" , "Net" , "Memory" , "DiskStats" , "DiskSizes" , "DefConfTest" ,
33
+ "Health" ]
32
34
commands = sys .argv [1 :]
33
35
if len (commands ) > 0 :
34
36
tool = commands [0 ]
@@ -71,14 +73,12 @@ def quit_handler(_signo=None, _stack_frame=None):
71
73
Plugin .Type = 'agent' # change plugin type for template generator
72
74
plugins = []
73
75
for klass in Plugin .only_child_subclasses ():
74
- if klass .__name__ in refactored_classes :
75
- if klass .__name__ == "PgWaitSampling" : # check if plugin is for EE
76
- if Plugin .VersionPG ['type' ] == 'PGEE' :
77
- plugins .append (klass (cfg ))
78
- elif klass .__name__ == "PgStatProgressVacuum" \
79
- and Plugin .VersionPG ['number' ] >= LooseVersion ('9.6' ):
76
+ if klass .__name__ == "PgWaitSampling" : # check if plugin is for EE
77
+ if Plugin .VersionPG ['type' ] == 'PGEE' :
80
78
plugins .append (klass (cfg ))
81
- else :
79
+
80
+ else :
81
+ if klass .__name__ != "Cfs" :
82
82
plugins .append (klass (cfg ))
83
83
types = args .plugin_type .split (',' )
84
84
# check if any plugin types is equal
@@ -89,9 +89,29 @@ def quit_handler(_signo=None, _stack_frame=None):
89
89
if len (types ) > 1 :
90
90
args .plugin_type = 'all'
91
91
if args .plugin_type == 'pg' or args .plugin_type == 'sys' or args .plugin_type == 'all' :
92
+ # check if conf file has a path
93
+ len_path = commands [2 ].rfind ("/" )
94
+ #print(len_path)
95
+ #print(len(commands[2]))
96
+ # get path for conf file and scripts
97
+ if len_path != - 1 :
98
+ path = commands [2 ][:len_path ] + "/scripts"
99
+ Plugin .PATH = path
100
+ else :
101
+ path = "./scripts"
102
+ Plugin .PATH = path
103
+ # create directory for scripts along the path of conf file if needed
104
+ if not os .path .exists (path ):
105
+ os .makedirs (path )
106
+ print ("directory for scripts has created" )
92
107
template = GetKeys ()
108
+ # write conf file
93
109
with codecs .open (commands [2 ], 'w' , 'utf-8' ) as f :
94
110
f .write (template .txt (args .plugin_type , plugins )) # pass command type
111
+ # write bash scripts for zabbix - agent to a file
112
+ for key in Scripts .Bash :
113
+ with codecs .open (path + "/" + key + ".sh" , 'w' , 'utf-8' ) as f :
114
+ f .write (Scripts .Bash [key ]) # pass script itself
95
115
else :
96
116
print_total_help ()
97
117
sys .exit (0 )
@@ -102,16 +122,11 @@ def quit_handler(_signo=None, _stack_frame=None):
102
122
elif commands [1 ] == 'template' :
103
123
plugins = []
104
124
for klass in Plugin .only_child_subclasses ():
105
- # temporary generate template for agent for classes that have been refactored
106
- if klass .__name__ in refactored_classes :
107
- if klass .__name__ == "PgWaitSampling" : # check if plugin is for EE
108
- if Plugin .VersionPG ['type' ] == 'PGEE' :
109
- plugins .append (klass (cfg ))
110
- elif klass .__name__ == "PgStatProgressVacuum" \
111
- and Plugin .VersionPG ['number' ] >= LooseVersion ('9.6' ):
112
- plugins .append (klass (cfg ))
113
- else :
125
+ if klass .__name__ == "PgWaitSampling" : # check if plugin is for EE
126
+ if Plugin .VersionPG ['type' ] == 'PGEE' :
114
127
plugins .append (klass (cfg ))
128
+ else :
129
+ plugins .append (klass (cfg ))
115
130
template = ZbxTemplate (args .template , args .application )
116
131
with codecs .open (commands [2 ], 'w' , 'utf-8' ) as f :
117
132
f .write (template .xml (plugins ))
@@ -124,18 +139,17 @@ def quit_handler(_signo=None, _stack_frame=None):
124
139
if klass .__name__ == "PgWaitSampling" : # check if plugin is for EE
125
140
if Plugin .VersionPG ['type' ] == 'PGEE' :
126
141
plugins .append (klass (cfg ))
127
- elif klass .__name__ == "PgStatProgressVacuum" \
128
- and Plugin .VersionPG ['number' ] >= LooseVersion ('9.6' ):
129
- plugins .append (klass (cfg ))
130
142
else :
131
- plugins . append ( klass ( cfg ))
132
- template = ZbxTemplate ( args . template ,
133
- args .application )
143
+ if klass . __name__ != "Cfs" :
144
+ plugins . append ( klass ( cfg ))
145
+ template = ZbxTemplate ( args . template , args .application )
134
146
with codecs .open (commands [2 ], 'w' , 'utf-8' ) as f :
135
147
f .write (template .xml (plugins ))
136
148
sys .exit (0 )
137
149
else :
138
150
print_total_help ()
151
+ else :
152
+ print_total_help ()
139
153
args , commands = parse_args ()
140
154
if len (commands ) > 0 :
141
155
print_total_help ()
0 commit comments