Skip to content

Commit

Permalink
Initial commit of the Zabbix vPoller Helper module
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeon committed Jan 9, 2014
1 parent 360e3d2 commit 5105512
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/vpoller/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__all__ = [ 'zabbix' ]
100 changes: 100 additions & 0 deletions src/vpoller/helpers/zabbix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Copyright (c) 2013-2014 Marin Atanasov Nikolov <[email protected]>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer
# in this position and unchanged.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""
vPoller Zabbix Helper module
The vPoller Zabbix Helper module provides routines for
translating a result vPoller message to a Zabbix-friendly format.
"""

import json

class HelperAgent(object):
"""
HelperAgent class of the Zabbix vPoller Helper
"""
def __init__(self, msg, data):
"""
Initializes a new HelperAgent object
Args:
msg (dict): The original request message
data (str): The result message data
"""
self.msg = msg
self.data = json.loads(data)

def run(self):
"""
Main Helper method
Processes the data and does any translations if needed
"""
# Check whether the request was successful first
if self.data['success'] != 0:
return json.dumps(self.data, indent=4)

# The original method requested from the vPoller Workers
method = self.msg['method']

# Methods that the Helper knows about and how to process
methods = {
'host.poll': self.zabbix_item_value,
'datastore.poll': self.zabbix_item_value,
'host.discover': self.zabbix_lld_data,
'datastore.discover': self.zabbix_lld_data,
}

result = methods[method]() if methods.get(method) else '[zbx-helper]: Do not know how to process method %s' % method

return result

def zabbix_item_value(self):
"""
Processes a single property value
Returns:
The property value from the result message
"""
pass

def zabbix_lld_data(self):
"""
Translates a discovery request to Zabbix LLD format
This method translates a discovery request to the
Zabbix Low-Level Discovery format.
For more information about Zabbix LLD, please refer to link below:
- https://www.zabbix.com/documentation/2.2/manual/discovery/low_level_discovery
"""
pass

0 comments on commit 5105512

Please sign in to comment.