44import sys
55import json
66from mamonsu .tools .zabbix_cli .request import Request
7+ from mamonsu .lib .parser import zabbix_msg
78
89
910class Operations (object ):
1011
11- _help_msg = """
12- Arguments must be:
13-
14- mamonsu zabbix template list
15- mamonsu zabbix template show <template name>
16- mamonsu zabbix template id <template name>
17- mamonsu zabbix template delete <template id>
18- mamonsu zabbix template export <file>
19-
20- mamonsu zabbix host list
21- mamonsu zabbix host show <host name>
22- mamonsu zabbix host id <host name>
23- mamonsu zabbix host delete <host id>
24- mamonsu zabbix host create <host name> <hostgroup id> <template id> <ip>
25- mamonsu zabbix host info templates <host id>
26- mamonsu zabbix host info hostgroups <host id>
27- mamonsu zabbix host info graphs <host id>
28- mamonsu zabbix host info items <host id>
29-
30- mamonsu zabbix hostgroup list
31- mamonsu zabbix hostgroup show <hostgroup name>
32- mamonsu zabbix hostgroup id <hostgroup name>
33- mamonsu zabbix hostgroup delete <hostgroup id>
34- mamonsu zabbix hostgroup create <hostgroup name>
35-
36- mamonsu zabbix item error <host name>
37- mamonsu zabbix item lastvalue <host name>
38- mamonsu zabbix item lastclock <host name>
39- """
12+ _help_msg = zabbix_msg
4013
4114 def __init__ (self , arg ):
42-
4315 self .arg = arg
16+
4417 if len (self .arg .commands ) < 2 :
45- self ._print_help ()
18+ if len (self .arg .commands ) == 0 or self .arg .commands [0 ] != 'version' :
19+ self ._print_help ()
4620
4721 self .req = Request (
4822 url = '{0}/api_jsonrpc.php' .format (arg .zabbix_url ),
@@ -57,6 +31,8 @@ def __init__(self, arg):
5731 return self .host (self .arg .commands [1 :])
5832 elif self .arg .commands [0 ] == 'item' :
5933 return self .item (self .arg .commands [1 :])
34+ elif self .arg .commands [0 ] == 'version' :
35+ return self .version (self .arg .commands [1 :])
6036 else :
6137 self ._print_help ()
6238
@@ -313,3 +289,16 @@ def item(self, args):
313289 except Exception as e :
314290 sys .stderr .write ('Error find: {0}\n ' .format (e ))
315291 sys .exit (3 )
292+
293+ def version (self , args ):
294+ if len (args ) != 0 :
295+ return self ._print_help ()
296+ try :
297+ self .req .set_user (None )
298+ self .req .set_passwd (None )
299+
300+ version = self .req .post (method = 'apiinfo.version' , params = [])
301+ print (str (version ))
302+ except Exception as e :
303+ sys .stderr .write ('Error find: {0}\n ' .format (e ))
304+ sys .exit (3 )
0 commit comments