SYNOPSIS

  package Zabbix::API::Unicorn;

  use parent qw/Zabbix::API::CRUDE/;

  # now override some virtual methods so that it works for the specific case of
  # unicorns

  sub id { ... }
  sub prefix { ... }
  sub extension { ... }

DESCRIPTION

This module handles most aspects of pushing, pulling and deleting the various types of Zabbix objects. You do not want to use this directly; a few abstract methods need to be implemented by a subclass.

1.

On top of Create, Read, Update and Delete, the Zabbix \s-1API\s0 also implements an Exists operation.

2.

It was written in a hurry.

METHODS

new([\s-1DATA\s0]) (constructor)

This is the standard, boilerplate Perl \s-1OO\s0 constructor. It returns a blessed hashref with the contents of \*(C`DATA\*(C', which should be a hash.

id([\s-1NEWID\s0]) (abstract method)

This method must implement a mutator for the relevant unique Zabbix \s-1ID\s0 (e.g. for hosts, \*(C`hostid\*(C'). What this means is, it must accept zero or one argument; if zero, return the current \s-1ID\s0 or undef; if one, set the current \s-1ID\s0 in the raw data hash (see the \*(C`data()\*(C' method) and return it.

node_id()

This method returns the current object's node \s-1ID\s0, for distributed setups. For objects in non-distributed setups, whose IDs do not include a node \s-1ID\s0, and objects that have never been pushed to the server, this method will return false.

prefix([\s-1SUFFIX\s0]) (abstract method)

This method must return a string that corresponds to its type (e.g. \*(C`host\*(C'). It should accept one optional argument to concatenate to the type; this kludge is necessary for types that have a different name depending on where they are used (e.g. graph items \*(-- not currently implemented as such \*(-- have a \*(C`graphitemid\*(C' but are referred to as \*(C`gitems\*(C' elsewhere). This is a class and instance method (and it returns the same thing in both cases so far). Warning: do not rely too much on this returning the correct compound name for any \s-1SUFFIX\s0, as I have implemented only those special cases that were of interest for the rest of the distribution.

extension() (abstract method)

This method must return a list that contains the various parameters necessary to fetch more data. (Returning an empty hash means that in most cases, only the IDs will be sent by the server.) E.g. for hosts, this is \*(C`return (output => 'extend')\*(C'.

name() (abstract method)

This method must return a preferably unique human-readable identifier. For instance, hosts return the \*(C`host\*(C' attribute.

data()

This is a standard accessor for the raw data as fetched from Zabbix and converted into a hashref. You can use \*(C`pull()\*(C' as a mutator on the same (but not for long).

pull([\s-1DATA\s0])

Without an argument, fetches the raw data from the Zabbix server and updates the Perl object appropriately. Calling \*(C`pull\*(C' on objects that do not have an \s-1ID\s0 set (they have not been fetched from the server, have never been pushed, or you have removed the \s-1ID\s0 yourself for obscure reasons) throws an exception. With a hashref argument, sets the raw data on the object directly, although this will change in a future version. In any case, this does not save your modifications for you. If you have changed the object's data in any way and not pushed the modifications to the server, they will be overwritten.

created()

This checks that the server knows about the object (has an object of the same type with the same \s-1ID\s0).

collides() (abstract method)

This method must return a list of objects (hashrefs of data, not instances of \*(C`Zabbix::API\*(C'!) that would cause the Zabbix server to reply \*(L"... already exists\*(R" if the invocant were created (as with a push).

push()

Create the object on the server if it doesn't exist, update it if it does. This distinction means that an object which has an \s-1ID\s0, but not a server representation, is in an illegal state; calling \*(C`push\*(C' on such an object throws an exception. Some classes (e.g. \*(C`Screen\*(C') override this to ensure that other objects they depend on are created before they are.

delete()

Deletes the object on the server and the local index (if you fetch it again it will be a different object from the one you're \*(L"holding\*(R").

RELATED TO Zabbix::API::CRUDE…

Zabbix::API, the Zabbix \s-1API\s0 documentation at <http://www.zabbix.com/documentation/start>.

AUTHOR

Fabrice Gabolde <[email protected]>

COPYRIGHT AND LICENSE

Copyright (C) 2011 \s-1SFR\s0

This library is free software; you can redistribute it and/or modify it under the terms of the GPLv3.