q1x / zabbix-gnomes

Various scripts to automate tasks in Zabbix
Other
179 stars 94 forks source link

Master #1

Closed intrepidsilence closed 9 years ago

intrepidsilence commented 9 years ago

Added zeventack.py - needs enhancement for error checking and input validity. Acknowledge an event with a message.

zevent.py -I "" -M ""

q1x commented 9 years ago

I think I'm missing the actual script in your pull request :-)

intrepidsilence commented 9 years ago

I could see it on the web page when logged in I thought. That's odd. Look one more time and if it is not there let me know. Remember I put it in devel.

On Mar 9, 2015, at 16:48, Raymond Kuiper notifications@github.com wrote:

I think I'm missing the actual script in your pull request :-)

— Reply to this email directly or view it on GitHub https://github.com/q1x/zabbix-gnomes/pull/1#issuecomment-77938928.

q1x commented 9 years ago

Nope, nothing here :-)

intrepidsilence commented 9 years ago

Strange. I'll try again later today.

On Mar 10, 2015, at 06:56, Raymond Kuiper notifications@github.com wrote:

Nope, nothing here :-)

— Reply to this email directly or view it on GitHub.

intrepidsilence commented 9 years ago

Hi there - I am not sure what I am doing wrong but I can't get git to let me commit it. Maybe I need permission. Not sure why the pull request did not contain the script itself. Anyway, here is the contents of the script:

!/usr/bin/python -d

import needed modules.

pyzabbix is needed, see https://github.com/lukecyca/pyzabbix

import pdb

pdb.set_trace()

import argparse import ConfigParser import os import os.path import sys import distutils.util from pyzabbix import ZabbixAPI

define config helper function

def ConfigSectionMap(section): dict1 = {} options = Config.options(section) for option in options: try: dict1[option] = Config.get(section, option) if dict1[option] == -1: DebugPrint("skip: %s" % option) except: print("exception on %s!" % option) dict1[option] = None return dict1

set default vars

defconf = os.getenv("HOME") + "/.zbx.conf" username = "" password = "" api = "" noverify = ""

Define commandline arguments

parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,description='Tries to acknowledge a given event ID with a message.', epilog=""" This program can use .ini style configuration files to retrieve the needed API connection information. To use this type of storage, create a conf file (the default is $HOME/.zbx.conf) that contains at least the [Zabbix API] section and any of the other parameters:

[Zabbix API] username=johndoe password=verysecretpassword api=https://zabbix.mycompany.com/path/to/zabbix/frontend/ no_verify=true

""")

parser.add_argument('-I', '--myeventid' ,help='Event ID to acknowledge.',required=True) parser.add_argument('-M', '--mymessage' ,help='Message to add to the acknowledged event.', required=True) parser.add_argument('-u', '--username', help='User for the Zabbix api') parser.add_argument('-p', '--password', help='Password for the Zabbix api user') parser.add_argument('-a', '--api', help='Zabbix API URL') parser.add_argument('--no-verify', help='Disables certificate validation when using a secure connection',action='store_true') parser.add_argument('-c','--config', help='Config file location (defaults to $HOME/.zbx.conf)') parser.add_argument('-e', '--extended', help='Extended output',action='store_true')

args = parser.parse_args()

load config module

Config = ConfigParser.ConfigParser() Config

if configuration argument is set, test the config file

if args.config: if os.path.isfile(args.config) and os.access(args.config, os.R_OK): Config.read(args.config)

if not set, try default config file

else: if os.path.isfile(defconf) and os.access(defconf, os.R_OK): Config.read(defconf)

try to load available settings from config file

try: username=ConfigSectionMap("Zabbix API")['username'] password=ConfigSectionMap("Zabbix API")['password'] api=ConfigSectionMap("Zabbix API")['api'] noverify=bool(distutils.util.strtobool(ConfigSectionMap("Zabbix API")["no_verify"])) except: pass

override settings if they are provided as arguments

if args.username: username = args.username

if args.password: password = args.password

if args.api: api = args.api

if args.no_verify: noverify = args.no_verify

test for needed params

if not username: sys.exit("Error: API User not set")

if not password: sys.exit("Error: API Password not set")

if not api: sys.exit("Error: API URL is not set")

Setup Zabbix API connection

zapi = ZabbixAPI(api)

if noverify is True: zapi.session.verify = False

Login to the Zabbix API

zapi.login(username, password)

##################################

Start actual API logic

##################################

pdb.set_trace()

mymsg=args.mymessage myevid=args.myeventid

try: result=zapi.event.acknowledge(eventids=myevid,message=mymsg) except: sys.exit("Error: Something went wrong while performing the update")

And we're done...

----- Original Message -----

From: "Raymond Kuiper" notifications@github.com To: "q1x/zabbix-gnomes" zabbix-gnomes@noreply.github.com Cc: "intrepidsilence" michael.spurlock@greyspaces.net Sent: Tuesday, March 10, 2015 6:56:54 AM Subject: Re: [zabbix-gnomes] Master (#1)

Nope, nothing here :-)

— Reply to this email directly or view it on GitHub .

q1x commented 9 years ago

Sorry for the late reply, I've just committed a new gnome (zeventacker.py). I changed the code a little bit though, so check syntax if you want to start using this one.

intrepidsilence commented 9 years ago

Cool, thanks!