Description Usage Arguments Details Note Author(s) Examples
ZabbixAPI
function enables easy and direct communication with Zabbix API
from R.
Each request to the Zabbix API
requires passing auth
authentication token.
Generation of the authentication token is explained here or
can be seen in Examples section.
1 2 3 4 |
server |
A character with base URI for zabbix web interface (omitting /api_jsonrpc.php). |
body |
A named list specifying |
user.agent, content.type |
Character arguments passed to POST through user_agent and content_type. |
encode |
The same as |
... |
Further arguments passed to POST. |
only.content, fromJSON, content.only.result |
|
Communication wih the Zabbix API
is described at Zabbix API Manual Reference and
relies on specifying methods of call and additional parameters in the JSON-RPC format. An example of such specification
can be found in the example of authenticating a user but in RZabbix this
should be specified in parameter body
where parameters are passed in the named list, where additional params
should be passed in jsonlite::unbox(data.frame())
.
See examples.
Bug reports and feature requests can be sent to https://github.com/MarcinKosinski/RZabbix/issues
Marcin Kosinski, m.p.kosinski@gmail.com
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 | ## Not run:
# user authentication
#####################
ZabbixAPI('http://localhost/zabbix',
body = list(method = "user.login",
params = jsonlite::unbox(
data.frame(user = "Admin",
password = "zabbix")))) -> auth
# request to get histoy of an item of 'item_id' number
######################################################
ZabbixAPI('http://localhost/zabbix',
body = list(method = "history.get",
params = jsonlite::unbox(
data.frame(output = "extend",
itemids = "item_id",
history = 0,
sortfield = "clock",
sortorder = "DESC",
limit = 10)
),
auth = auth))
# API info
##########
ZabbixAPI('http://localhost/zabbix',
body = list(method = "apiinfo.version"))
# fromJSON example for get event data fo object with 'object_id' number
#######################################################################
library(jsonlite)
paste0('{
"method": "event.get",
"params": {
"output": "extend",
"select_acknowledges": "extend",
"objectids": "object_id",
"sortfield": ["clock", "eventid"],
"sortorder": "DESC"
},
"auth": "', auth, '"
}') -> json_rpc
ZabbixAPI('http://localhost/zabbix',
body = fromJSON(json_rpc)) -> event.info
# colnames - https://www.zabbix.com/documentation/3.0/manual/api/reference/event/object
event.info %>%
select(value, clock) %>%
mutate(clock =
as.POSIXct(as.numeric(clock),
tz = "GMT",
origin = "1970-01-01")) -> clock2viz
list2bind <- list()
for(i in 1:(nrow(clock2viz)-1)) {
data.frame(
times =
seq(from = clock2viz$clock[i+1],
to = clock2viz$clock[i],
by = "min") %>%
head(-1),
status = clock2viz$value[i+1],
stringsAsFactors = FALSE) ->
list2bind[[i]]
}
library(ggplot2)
do.call(bind_rows, list2bind) %>%
ggplot(aes(x=times, y = status)) +
geom_point(size = 0.1)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.