https://github.com/adjust/zabbix-api
perl zabbix bindings
https://github.com/adjust/zabbix-api
Last synced: 9 months ago
JSON representation
perl zabbix bindings
- Host: GitHub
- URL: https://github.com/adjust/zabbix-api
- Owner: adjust
- License: mit
- Created: 2014-01-23T15:19:52.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-08-21T10:35:38.000Z (almost 12 years ago)
- Last Synced: 2024-11-16T16:14:28.710Z (over 1 year ago)
- Language: Perl
- Size: 270 KB
- Stars: 1
- Watchers: 74
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
zabbix-api
==========
perl zabbix bindings
## Api usage
First create a ZabbixApi Object:
```perl
use ZabbixApi;
my $api = ZabbixApi->new(
user => 'winston',
pw => 'gayhaim69',
url => 'http://my.domain.com/api_jsonrpc.php',
);
```
Now you can use the zabbix api described in the documentation like this.
Let us first get the hostgroup id of `Linux servers`.
```perl
# set api method
$zabbix->set_method('hostgroup.get');
# wrapper around output: set to 'extend'
$zabbix->payload->set_output(3);
# perform api call
$zabbix->process;
# find the Object describing Linux servers group
my $o = $zabbix->find_by( 'name', 'Linux servers' );
# we got a hash
my $id = $$o{'groupid'};
# clear the api buffer before the next action
$zabbix->clear;
```
Now we can create a host that is in this hostgroup
```perl
# set api method
$zabbix->set_method('host.create');
# add the new hostgroup
$zabbix->add_params( { groups => [ { 'groupid' => $id } ] } );
# add the interfaces
$zabbix->add_params(
{
interfaces =>
[
{
'useip' => 1,
'ip' => '188.187.123.123',
'port' => '10050',
'dns' => 'test.com',
'type' => 1,
'main' => 1,
}
]
}
);
# add the new hostname
$zabbix->add_params( { 'host' => 'testhost' } );
# perform the api call which creates the hostgroup
$zabbix->process;
```
Of course you can add all the params in one `add_params` call. It takes every hash ref as an argument.