-
Notifications
You must be signed in to change notification settings - Fork 9
/
zapish.inc.3
243 lines (243 loc) · 5.13 KB
/
zapish.inc.3
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
'\" t
.\" Title: zapish.inc
.\" Author: Tomasz Kłoczko <[email protected]>
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\" Date: 06/11/2018
.\" Manual: Library functions
.\" Source: zapish.inc
.\" Language: English
.\"
.TH "ZAPISH\&.INC" "3" "06/11/2018" "zapish\&.inc" "Library functions"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
zapish.inc \- Zabbix API SHell binding
.SH "SYNOPSIS"
.HP \w'\fB\&.\ /usr/libexec/zapish\&.inc\fR\ 'u
\fB\&. /usr/libexec/zapish\&.inc\fR
.SH "DESCRIPTION"
.PP
The
\fBzapish\&.inc\fR
is the file to include in own SH/bash scripts with few functions which make calling Zabbix API easy\&.
.PP
It consists of few functions for:
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
construct JSON string fields like string, numeric and arrays
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
the main
\fBzabbix_api\fR
function which is used to call Zabbix API
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
JSON return values parser/extractor
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
the
\fBzapish_init\fR
function which reads
\fB~/\&.zapish\&.rc\fR
configuration file or initialize if it does not exist
.RE
.PP
At the moment zapish\&.inc is not fully POSIX SH compliant because it uses in few places "local" keyword to define functions local variables\&. However, the intention is to rewrite it to make it fully POSIX SH compliant code\&.
.SH "FUNCTIONS"
.PP
\fBNOTE:\fRBelow all json_* functions as last argument must have empty string ("")\&.
.PP
\fBjson_array_num\fR
.RS 4
This function prints string in the format of the JSON table of numbers\&.
.sp
Syntax:
\fBjson_array_num\fR
"array_name" num1 [[num2] \&.\&.\&.] ""
.RE
.PP
\fBjson_array_str\fR
.RS 4
This function prints string in the format of the JSON table of strings\&.
.sp
Syntax:
\fBjson_array_str\fR
"array_name" "str1" [["str2"] \&.\&.\&.] ""
.RE
.PP
\fBjson_list\fR
.RS 4
This function prints string in the format of the JSON list of unspecified elements\&.
.RE
.PP
\fBjson_num\fR
.RS 4
This function prints list of parameters in the format of the JSON field with list of numbers\&.
.sp
Syntax:
\fBjson_num\fR
"list_num_name" num1 [[num2] \&.\&.\&.] ""
.RE
.PP
\fBjson_str\fR
.RS 4
This function prints list of parameters in the format of the JSON field with list of strings\&.
.sp
Syntax:
\fBjson_num\fR
"list_str_name" "str1" [["str2"] \&.\&.\&.] ""
.RE
.PP
\fBzabbix_api\fR
.RS 4
The main zapish function used to call any Zabbix API\&. This function expects only one parameter in which should be
.RE
.SH "CONFIGURATION"
.PP
The
\fBzapish\&.inc\fR
functions uses following configuration variables in
\fB~/\&.zapish\&.rc\fR:
.PP
\fBzapish_url\fR
.RS 4
URL of the Zabbix API gateway used by
\fBzapish\&.inc\fR\&.
.RE
.PP
\fBzapish_auth\fR
.RS 4
Zabbix API authentication token generated by
\fBuser\&.login\fR
API function\&.
.RE
.PP
The
\fB~/\&.zapish\&.rc\fR
file is generated automatically if it does not exist by any script which includes
\fBzapish\&.inc\fR\&. It will prompt to enter the username, password and the Zabbix API gateway URL\&. If authentication will be correct generated authentication token hash and API gateway URL will be stored in
\fB~/\&.zapish\&.rc\fR\&.
.SH "FILES"
.PP
\fB/usr/libexec/zapish/zapish\&.inc\fR
.RS 4
The default location of the
\fBzapish\&.inc\fR
include file\&.
.RE
.SH "EXIT CODES"
.sp
.it 1 an-trap
.nr an-no-space-flag 1
.nr an-break-flag 1
.br
.B Table\ \&1.\ \& Functions defined in zapish\&.inc may exit with the following exit codes:
.TS
allbox tab(:);
cB lB.
T{
Exit code
T}:T{
Description
T}
.T&
c l
c l
c l
c l
c l.
T{
0
T}:T{
Success
T}
T{
1
T}:T{
Zabbix API authentication error
T}
T{
2
T}:T{
First use of zapish\&. Initialization has been done and \fB~/\&.zapish\&.rc\fR file has been created sucessfully
T}
T{
3
T}:T{
The zabbix_api() called without arguments
T}
T{
4
T}:T{
The zabbix_api() call error
T}
.TE
.sp 1
.SH "SEE ALSO"
.PP
\fBsh\fR(1),
\fBbash\fR(1)\&.
.PP
\m[blue]\fB\%https://github.com/kloczek/zapish/\fR\m[]
.PP
\m[blue]\fB\%https://www.zabbix.com/documentation/3.4/manual/api/\fR\m[]
.SH "AUTHOR"
.PP
\fBTomasz Kłoczko\fR <\&kloczek@fedoraproject\&.org\&>
.RS 4
.RE
.RS 4
Author
.RE
.SH "COPYRIGHT"
.br
Copyright \(co 2017-2018
.br