Aug 102016
 

I wanted to build a menu item in Zabbix to open a ticket against a host in Zabbix so that we could flag one for attention.

OSTicket Configuration

In OSTicket, the API needs to be configured to allow for API requests to be made. This is as simple as logging into the Admin interface of OSTicket and going to Manage -> API Keys, and then adding one with the following parameters:

Status: Active
IP Address: IP Address of the Zabbix server
[x] Can Create Tickets (XML/JSON/EMAIL)

Once the key is added, you just need to ensure that the Zabbix server can communicate with the OSTicket server on port 80, or 443 if you’re using HTTPS.

Zabbix Configuration

The Zabbix side requires a new menu item under Administration -> Scripts, and a script that I’ve provided at the end.
The menu item is configured with the path of the script, then the host details.

In this example, I’ve created a directory called userscripts and placed the python script into there.
The menu item/script uses the following command line –
/usr/lib/zabbix/userscripts/raiseticket.py --issuesummary "Issue on {HOST.DNS}" --issuedetails "Issue on {HOST.DNS}"
The Issue summary can be changed in the command line.

The script is available below. You just need to update the OSTIcket URL, API Key,Topic ID, and the user details for the ticket.
After the script has been copied to the correct location, you will be able to raise tickets on the host as required.


#!/usr/bin/python
import argparse
import requests
import json

parser = argparse.ArgumentParser(description="Raises tickets in OSTicket")
parser.add_argument('--issuesummary', required=True, help='The issue summary that will appear in osTicket', dest='summary')
parser.add_argument('--issuedetails', required=True, help='The issue detail that will appear in osTicket', dest='detail')
args = parser.parse_args()

url = "http://<OSTICKET URL>/api/tickets.json"
key = "<OSTicket API Key>"

data = {
"name":"USER",
"email":"USER@EXAMPLE.COM",
"phone":"PHONE",
"subject":args.summary,
"message":args.detail,
"topicId":TOPICID
}

headers = {
"X-API-Key": key
}

r = requests.post(url,data=json.dumps(data),headers=headers)
print r.text

Share

  5 Responses to “Integrating Zabbix with OSTicket”

  1. Opinion on both Zabbix and OSTicket?

    • Zabbix is awesome. Easy to setup and use, however it chews through disk IO.
      OSTicket is pretty easy to setup as well, free for self hosted and very customisable.
      I’m using both at work and it’s working out pretty well so far.

  2. Hello, I have configure the same as you told. But it is not working. Can you please help me on this? This is very much urgent for me!

    • What’s not working?

      • Unable to create new ticket: validation errors:
        34: Module is a required field
        err: Missing or invalid data – check the errors and try again

        I have a Mandatory Form in OSTicket called “Module”, Can you please help me to get how to configure the Python Script.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)