-
Notifications
You must be signed in to change notification settings - Fork 12
/
zabbix_get-completion
130 lines (124 loc) · 4.8 KB
/
zabbix_get-completion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#
# Bash completion for zabbix_get
#
shopt -s extglob
_zabbix_get()
{
local cur prev opts unique_opts nonunique_opts unique_opts_space nonunique_opts_space opt option
local keys
COMPREPLY=()
_get_comp_words_by_ref -n = cur prev
unique_opts="-h|--help|-V|--version"
nonunique_opts="-s|-p|-I|-k|--host|--port|--source-address|--key|--tls-connect|--tls-ca-file|--tls-crl-file|--tls-agent-cert-issuer|--tls-agent-cert-subject|--tls-cert-file|--tls-key-file|--tls-psk-identity|--tls-psk-file|--tls-cipher|--tls-cipher13"
unique_opts_space=${unique_opts//|/ }
nonunique_opts_space=${nonunique_opts//|/ }
keys="agent.hostname agent.ping agent.version kernel.maxfiles kernel.maxproc net.dns[ net.dns.record[ \
net.if.collisions[ net.if.discovery net.if.in[ net.if.out[ net.if.total[ net.tcp.listen[ net.tcp.port[ net.tcp.service[ \
net.tcp.service.perf[ net.udp.listen[ net.udp.service[ net.udp.service.perf[ proc.cpu.util[ proc.mem[ proc.num[ sensor[ \
service.discovery service.info[ system.boottime system.cpu.discovery system.cpu.intr system.cpu.load[ system.cpu.num[ \
system.cpu.switches system.cpu.util[ system.hostname[ system.hw.chassis[ system.hw.cpu[ system.hw.devices[ \
system.hw.macaddr[ system.localtime[ system.run[ system.stat[ system.sw.arch system.sw.os[ system.sw.packages[ \
system.swap.in[ system.swap.out[ system.swap.size[ system.uname system.uptime system.users.num vfs.dev.read[ \
vfs.dev.write[ vfs.file.cksum[ vfs.file.contents[ vfs.file.exists[ vfs.file.md5sum[ vfs.file.regexp[ vfs.file.regmatch[ \
vfs.file.size[ vfs.file.time[ vfs.fs.discovery vfs.fs.inode[ vfs.fs.size[ vm.memory.size[ web.page.get[ web.page.perf[ \
web.page.regexp[ eventlog[ net.if.list perf_counter[ proc_info[ service_state[ services[ wmi.get["
opts=" $unique_opts_space $nonunique_opts_space "
for (( i=1; i<=$[${#COMP_WORDS[@]}-1]; ++i )) ; do
opt=${COMP_WORDS[$i]}
[[ $opt =~ --*[spIkhVvt].* ]] && {
option=$opt
} || {
continue
}
# if a unique option has been supplied, do not offer any other options
[[ $option == @($unique_opts) ]] && {
return 1
}
# if a non-unique option has been supplied, remove all unique options and already used options
[[ $option == @($nonunique_opts) ]] && opts="${opts/$unique_opts_space/}"
opts=${opts/ $option / }
# remove alternatives and exclusives
case $option in
-s) opts="${opts/ --host/}" ;;
--host) opts="${opts/ -s/}" ;;
-I) opts="${opts/ --source-address/}" ;;
--source-address) opts="${opts/ -I/}" ;;
-p) opts="${opts/ --port/}" ;;
--port) opts="${opts/ -p/}" ;;
-k) opts="${opts/ --key/}" ;;
--key) opts="${opts/ -k/}" ;;
esac
# these are exclusive
case "${option}" in
-@(-tls-ca-file|-tls-crl-file|-tls-agent-cert-issuer|-tls-agent-cert-subject|-tls-cert-file|-tls-key-file))
opts="${opts/ --tls-psk-identity/}"
opts="${opts/ --tls-psk-file/}"
;;
-@(-tls-psk-identity|-tls-psk-file))
opts="${opts/ --tls-ca-file/}"
opts="${opts/ --tls-crl-file/}"
opts="${opts/ --tls-agent-cert-issuer/}"
opts="${opts/ --tls-agent-cert-subject/}"
opts="${opts/ --tls-cert-file/}"
opts="${opts/ --tls-key-file/}"
;;
--tls-connect)
[[ ${COMP_WORDS[$[$i+1]]} == unencrypted ]] && {
opts="${opts/ --tls-ca-file/}"
opts="${opts/ --tls-crl-file/}"
opts="${opts/ --tls-agent-cert-issuer/}"
opts="${opts/ --tls-agent-cert-subject/}"
opts="${opts/ --tls-cert-file/}"
opts="${opts/ --tls-key-file/}"
opts="${opts/ --tls-psk-identity/}"
opts="${opts/ --tls-psk-file/}"
}
[[ ${COMP_WORDS[$[$i+1]]} == psk ]] && {
opts="${opts/ --tls-ca-file/}"
opts="${opts/ --tls-crl-file/}"
opts="${opts/ --tls-agent-cert-issuer/}"
opts="${opts/ --tls-agent-cert-subject/}"
opts="${opts/ --tls-cert-file/}"
opts="${opts/ --tls-key-file/}"
}
[[ ${COMP_WORDS[$[$i+1]]} == cert ]] && {
opts="${opts/ --tls-psk-identity/}"
opts="${opts/ --tls-psk-file/}"
}
;;
esac
done
case "${prev}" in
-@(-tls-psk-file|-tls-ca-file|-tls-crl-file|-tls-cert-file|-tls-key-file))
compopt -o default
COMPREPLY=()
return 0
;;
-@(s|-host))
COMPREPLY=( $(compgen -A hostname ${cur}) )
return 0
;;
-@(I|-source-address))
COMPREPLY=( $(compgen -W "$(ip -o addr show | awk '{sub(/\/.*/,"",$4); print $4}')" -- ${cur}) )
return 0
;;
-@(k|-key))
COMPREPLY=( $(compgen -W "${keys}" -- ${cur}) )
if [[ $COMPREPLY =~ "[" ]]; then
compopt -o nospace
fi
return 0
;;
-@(p|-port|-tls-agent-cert-issuer|-tls-agent-cert-subject|-tls-psk-identity))
return 1
;;
--tls-connect)
_zabbix-utils-tls-connect "$cur" get
return 0
;;
*)
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
}
complete -F _zabbix_get zabbix_get