-
Notifications
You must be signed in to change notification settings - Fork 11
/
zabbix_sender-completion
138 lines (132 loc) · 4.69 KB
/
zabbix_sender-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
131
132
133
134
135
136
137
138
#
# Bash completion for zabbix_sender
#
shopt -s extglob
_zabbix_sender()
{
local cur prev opts unique_opts nonunique_opts unique_opts_space nonunique_opts_space opt option
COMPREPLY=()
_get_comp_words_by_ref -n = cur prev
unique_opts="-h|--help|-V|--version"
nonunique_opts="-c|-k|-i|-I|-o|-p|-r|-s|-T|-v|-z|--host|--key|--input-file|--port|--real-time|--source-address|--with-timestamps|--value|--verbose|--zabbix-server|--config|--tls-connect|--tls-ca-file|--tls-crl-file|--tls-server-cert-issuer|--tls-server-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//|/ }
opts=" $unique_opts_space $nonunique_opts_space "
for (( i=1; i<=$[${#COMP_WORDS[@]}-1]; ++i )) ; do
opt=${COMP_WORDS[$i]}
[[ $opt =~ --*[cspiorTtzIkhVvw].* ]] && {
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/}" ;;
-c) opts="${opts/ --config/}" ;;
--config) opts="${opts/ -c/}" ;;
-z) opts="${opts/ --zabbix-server/}" ;;
--zabbix-server) opts="${opts/ -z/}" ;;
-o) opts="${opts/ --value/}" ;;
--value) opts="${opts/ -o/}" ;;
-i) opts="${opts/ --input-file/}" ;;
--input-file) opts="${opts/ -i/}" ;;
-T) opts="${opts/ --with-timestamps/}" ;;
--with-timestamps) opts="${opts/ -T/}" ;;
-r) opts="${opts/ --real-time/}" ;;
--real-time) opts="${opts/ -r/}" ;;
-v) opts="${opts/ --verbose/}" ;;
--verbose) opts="${opts/ -v/}" ;;
esac
# these are exclusive
case "${option}" in
-@(o|-value))
opts="${opts/ -i/}"
opts="${opts/ --input-file/}"
opts="${opts/ --with-timestamps/}"
opts="${opts/ -T/}"
opts="${opts/ --real-time/}"
opts="${opts/ -r/}"
;;
-@(i|-input-file|T|-with-timestamps|r|-real-time))
opts="${opts/ -o/}"
opts="${opts/ --value/}"
;;
-@(-tls-ca-file|-tls-crl-file|-tls-server-cert-issuer|-tls-server-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-server-cert-issuer/}"
opts="${opts/ --tls-server-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-server-cert-issuer/}"
opts="${opts/ --tls-server-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-server-cert-issuer/}"
opts="${opts/ --tls-server-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
-@(c|i|-config|-input-file|-tls-psk-file|-tls-ca-file|-tls-crl-file|-tls-cert-file|-tls-key-file))
compopt -o default
COMPREPLY=()
return 0
;;
-@(s|z|-host|-zabbix-server))
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
;;
-@(p|-port|o|-value|k|-key|-tls-server-cert-issuer|-tls-server-cert-subject|-tls-psk-identity))
return 1
;;
--tls-connect)
_zabbix-utils-tls-connect "$cur" sender
return 0
;;
*)
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
}
complete -F _zabbix_sender zabbix_sender