##  Mojo::Zabbix 

Mojo::Zabbix  is a simple perl wrapper of Zabbix API. We build only authentication 
and request methods and few helper methods to simplify calling methods 
such ascreate/get/update/delete/exists. 

## ������������

   Mojo::Zabix - ������zabbix api������������������������������������������perl������������
������������zabbix������������������������������������������������������������`create`/`get`
/`update`/`delete`/`exists`������������������������������������������`Mojo::useragent`���������
���`Mojo:DOM`������������������������������

  ���������������`Mojo`���������������`cpan`���������`cpanm Mojo::Zabbix`

### The more details ,please visting the Zabbix API documentation pages .

    - [Zabbix API Wiki](http://www.zabbix.org/)
    - [Zabbix 1.8 API](http://www.zabbix.com/documentation/1.8/api)
    - [Zabbix 2.0 API](http://www.zabbix.com/documentation/2.0/)
    - [Zabbix 2.2 API](https://www.zabbix.com/documentation/2.2/)
    - [Zabbix 3.0 API](https://www.zabbix.com/documentation/3.0/)
    - [Zabbix 3.2 API](https://www.zabbix.com/documentation/3.2/)
    - [Zabbix 3.4 API](https://www.zabbix.com/documentation/3.4/)
    - [Zabbix 4.0 API](https://www.zabbix.com/documentation/4.0/)

### Test

The module is compatible and tested with Zabbix less version 4.0

���������������������4.0���������������������������4.0������������������������4.x������������������������������������

## Example

```
     use Mojo::Zabbix;

     my $z = Net::Zabbix->new(
	url => "https://server/zabbix/", 
	username => 'user', 
	password => 'pass',
	verify_ssl => 0,
	debug => 1,
	trace => 0,
     );

     my $r = $z->get("host", {
            filter => undef,
            search => {
            host => "test",
        },
     }
     );

```
#### A example for print the zabbix api version ������zabbix���������������.

    print $z->get("apiinfo.version",)->{result},"\n";

#### A example for get the new warn message of triggerid ������������������������.

```
      print getTriggers($z); # ���������������������������������������Mojo::Zabbix::APP

      sub getTriggers {
        my $z=shift;
        my $ysterday=localtime(time()-24*3600);
        my $r = $z->get("trigger", {
                filter => {value => 1,
                           lastChangeSince => "$ysterday",
                  'withUnacknowledgedEvents'=>1,
                },
                output => ["","triggerid","description","priority"],
               sortfield =>"priority",
                sortorder => "DESC",
                expandData=>"host",

         },
         );
         my $result;
         my $host=$r->{'result'};
         for (@$host){
           $result.="$_->{'host'}:".$_->{'description'}."\n" ;
         }

        return $result;
      }

```

## The result all ������������: 

    xxx.xxx.xx.55: {HOST.CONN}������������84������down
    xxx.xxx.xx.55: {HOST.CONN}������������81������down
    xxx.xxx.xx.55: {HOST.CONN}������������82������down
    xxx.xxx.xx.55.9: {HOST.CONN}������������80������down
    xxx.xxx.xx.12: {HOST.NAME} ���������������������������������������
    xxx.xxx.xx.124: ������sdb���������������95%���������������{ITEM.LASTVALUE}
    xxx.xxx.xx.44: ������sdb���������������95%���������������{ITEM.LASTVALUE}
    xxx.xxx.xx.45: ������sdb���������������95%���������������{ITEM.LASTVALUE}
    xxx.xxx.xx.33: ������sdb���������������95%���������������{ITEM.LASTVALUE}
    xxx.xxx.xx.56: ������sda���������������95%���������������{ITEM.LASTVALUE}
    xxx.xxx.xx.57: ������sda���������������95%���������������{ITEM.LASTVALUE}


## ���������������������������webqq������webwx������������hosts���������������������

    XX_10.2.7.20_
    ������������:
    
    ESTABLISHED������ - { connections.status[ESTABLISHED] } : 9
    SYN������ - { connections.status[SYN] } : 0
    ������$1��������������� - { net.if.out[bond0] } : 5176
    ������ - { system.cpu.load[,avg1] } : 0.000000
    $1������inode��������� - { vfs.fs.inode[/,pfree] } : 99.788211
    $1������������������ - { vfs.fs.size[/,pfree] } : 99.269724
    ������������ - { vm.memory.size[available] } : 261874798592
    ��������������� - { vm.memory.size[pused] } : 4.720467
    ��������������� - { vm.memory.size[total] } : 270763327488
    
## Mojo-Zabbix-APP

The application of Mojo-Zabbix module���
Get data from zabbix data include host���items, Triggers and warns and so on.

   ���Mojo::Zabix���������������������������zabbix api������������������������
���������������������zabbix���������������������zabbix���������������������������������������������������������
������������������������������������������������

### Example

     use Mojo::Zabbix::APP;

     my @myzinfo = <DATA>; ##(get zabbix info from __DATA__ )

#### Define for debug and traceing processe infomaition������������������������������

    my $DEBUG=0;
    my $TRACE=0;

#### ������zabbix���������

```
 my @myzinfo = ('test1  http://test1/zabbix    testuser pass');

 @���������������������������������������������������������zabbix ������������������

    for (@myzinfo) {
 
     next if /^#/;
     next if /^\s*$/;
     my ( $name, $url,$user, $pass ) = split;
     print "\n$name\n";
     my $z;

     eval { $z = initZ( $url,$user,$pss ); };

     if ($@) {

        print "Error $@!\n";
 
     } else {
         ## Print the version of zabbix api. ������zabbix ������ 
        
         pVersion($z);
       ## Print all host lists��� ���������������������������
        print  getAllhost($z);
       ## Print warning info of Triggers���������������������������������������������
        pTriggers($z);
       
       ## Print the history data of given items, default for past 24 hours.
       ## ������������������������item������������������������������������������������������24������������
       pHitems($z); # ������������������������

     }

    }

```

## ������������

    name

    Warning info of Triggers

    2016-10-19 23:29:57  : 192.168.1.* : {HOST.NAME}������80������������
    2016-10-19 22:58:28  : 192.168.2.* : ������������/etc/sysconfig/������������
    2016-10-19 22:24:32  : 192.168.3.* : ������������/etc/init.d/������������
    2016-10-19 19:12:53  : 192.168.3.* : ������sda IO���������������95%
    2016-10-19 18:03:03  : 192.168.4.* : Too many processes on {HOST.NAME}


## More,������������

wo can add the program to crontab  and gain the result for mail
or some Im tool.

������������������cron������������������������������������������������IM���������qq���������������
������������[Mojo-webqq](https://github.com/sjdy521/Mojo-Webqq)���������,������
������������������������


## Git repo
 
[github](https://github.com/bollwarm/Mojo-Zabbix)

[oschina](https://gitee.com/ijz/Mojo-Zabbix.git) 

## AUTHOR
 
[mail to me](bollwarm@ijz.me)

[web|blog](http://ijz.me)

## License

This software is copyright (c) 2016 by oragnge.

This is free software; you can redistribute it and/or modify
 it under the same terms as the Perl 5 programming language system itself..