Giter VIP home page Giter VIP logo

argus_ticket_rt's Introduction

argus_ticket_rt

This is a plugin to create tickets in Request Tracker from Argus

The API supported is RT V2. RT 4.4 needs RT::Extension::REST2 to support V2, while RT 5.0.0 and later has the support included.

Settings

  • TICKET_PLUGIN must be set to "argus_ticket_rt.RequestTrackerPlugin"

  • TICKET_ENDPOINT: Link to instance, absolute URL

  • TICKET_AUTHENTICATION_SECRET: Standard username/password or token:

    {
        "username": username,
        "password": password
    }
    

    or

    {
        "token": token
    }
    

    It is recommended to create an RT API user and to ensure that that user has the necessary authorization for creating tickets in the relevant queue.

    Username and password login can be disabled if the login happens through an external provider. In that case an authentication token should be used.

    If authentication tokens are enabled in RT they can be created under "Logged in as ..." -> "Settings" -> "Auth tokens".

    This could however be turned off side-wide or just for that specific user. In that case please contact the responsible RT administrator.

  • TICKET_INFORMATION:

    Queue (obligatory)

    {
        "queue": queue_name
    }
    

    Custom fields (optional)

    There are two ways of automatically filling custom fields:

    1. Custom fields that are always the same, independent of the incident. These will be set in custom_fields_set with the name of the custom field as key and the fixed value as value.

      {
          "custom_fields_set" : {
              "name_of_custom_field": set_value,
          }
      }
      
    2. Custom fields that are filled by attributes of the Argus incident. These are set in custom_fields_mapping with the name of the custom field as key and the name of the attribute as it is returned by the API as value (e.g. start_time). If the information can be found in the tags the value consists of a dictionary with tag as the key and the name of the tag as the value (e.g. {"tag": "host"}).

      {
          "custom_fields_mapping" : {
              "name_of_custom_field": attribute_of_incident,
              "name_of_custom_field": {"tag": name_of_tag},
          }
      }
      

Library

The library used is rt instead of rt-client because "rt-client" does not support token authentication.

Code style

argus_ticket_rt uses black as a source code formatter. Black can be installed by running

$ pip install black

A pre-commit hook will format new code automatically before committing. To enable this pre-commit hook, run

$ pre-commit install

argus_ticket_rt's People

Contributors

hmpf avatar johannaengland avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

hmpf

argus_ticket_rt's Issues

Bug: unhandled exception

Internal Server Error: /api/v2/incidents/34521/automatic-ticket/
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/usr/local/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/local/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/usr/local/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/app/Argus/src/argus/incident/views.py", line 329, in update
    url = ticket_class.create_ticket(serialized_incident)
  File "/usr/local/lib/python3.10/site-packages/argus_ticket_rt.py", line 138, in create_ticket
    custom_fields = cls.get_custom_fields(
  File "/usr/local/lib/python3.10/site-packages/argus_ticket_rt.py", line 67, in get_custom_fields
    custom_fields[key] = incident_tags[field["tag"]]
KeyError: 'kundetjeneste'

It is unclear whether kundetjeneste is missing from "custom_fields" or "incident_tags" but missing keys in both ought to be handled.

Endless loop when failing to connect to RT

2022-12-09 13:41:57,459 rt_client.v2.client DEBUG    RT Client Authentication Failure
2022-12-09 13:41:57,459 argus_ticket_rt ERROR    Request Tracker: Client could not be created.
Traceback (most recent call last):
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/urllib3/connection.py", line 169, in _new_conn
    conn = connection.create_connection(
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/urllib3/util/connection.py", line 96, in create_connection
    raise err
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/urllib3/util/connection.py", line 86, in create_connection
    sock.connect(sa)
OSError: [Errno 101] Network is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/urllib3/connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/urllib3/connectionpool.py", line 382, in _make_request
    self._validate_conn(conn)
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn
    conn.connect()
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/urllib3/connection.py", line 353, in connect
    conn = self._new_conn()
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/urllib3/connection.py", line 181, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7fc251d04ac0>: Failed to establish a new connection: [Errno 101] Network is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/urllib3/connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/urllib3/util/retry.py", line 574, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='rt.example.com', port=443): Max retries exceeded with url: /NoAuth/Login.html (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fc251d04ac0>: Failed to establish a new connection: [Errno 101] Network is unreachable'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/argus_ticket_rt.py", line 53, in create_client
    client = Client(
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/rt_client/client.py", line 23, in Client
    return _CLIENTS[str(version).lower()](*args, **kwargs)
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/rt_client/v2/client.py", line 65, in __init__
    self.authenticate()
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/rt_client/v2/client.py", line 80, in authenticate
    self.sess.post(
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/requests/sessions.py", line 590, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "foo/.virtualenvs/argus/lib/python3.10/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='rt.example.com', port=443): Max retries exceeded with url: /NoAuth/Login.html (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fc251d04ac0>: Failed to establish a new connection: [Errno 101] Network is unreachable'))

Generic changes to look of RT ticket

  • body: nicely formatted view of whole incident (similar to frontend look)
  • links - refers to: link back to incident (main url can be found in settings), details_url

What do we really want in the README

As is, the README is a good starting point, and we can start using the plugin without polishing it further. However, since it also is the only real place to document the plugin (docs/ would be overkill I feel) and it feels a bit too short and sweet I'll write down what I think would make it better, especially when we have a few more plugins in place.

  • Maybe a pointer to argus-server's docs about ticket plugins, and especially the list of other plugins, when we have that list!
  • Badges! Everything is better with badges. Makes the project look more mature than it is ;)
  • Mention that the settings talked about is the instance specific Django settings file
  • How to install
  • How to test
  • File-hierarchy and some comments pointing out the important bits, to make it easier for developers making their own plugins to understand what they need to focus on, for instance the requirements-*-files are generated by tox!

All of this should eventually go in the cookiecutter of course. And there should probably be a link to the cookiecutter, again, to make it easier for plugin-developers.

Use custom fields in RT

It should possible to add a mapping to the settings that specifies custom fields and which part of the serialized incident to use for it, which will then be used when creating a new ticket.

Things that the Sikt Service Center needs:

  • kategori: "incident"
  • tidspunkt start: incident start
  • tidspunkt stop: incident end (if exists)
  • kundetjenester: tag kundetjenester
  • utstur: tag host
  • description: description

Error handling: Log from the exception itself

Note: One idea I saw regarding logging of exceptions: log from the exception itself.

import logging

class MyError(Exception):
  "Helpful docs"

  def __init__(self, msg):
    logging.exception(msg)
    super().__init__(msg)

The above is as minimal as it gets, the whole thing was a bit more elaborate: Stackoverflow: comment to "Logging and raising an exception". Needs testing to see if the traceback is saved.

As later polish, this would cut down on code in plugins even further.

Originally posted by @hmpf in #24 (review)

Incorrect start and stop times when creating a case for RT

https://ARGUSHOST/incidents/34795/

The start time visible in Request Tracker is 1 hour behind the correct time as seen in Argus.
The end time was not set in Argus at the time of creation (still an Open alarm), but the end-time (Tidspunkt - Slutt) in RT was still set to an earlier timestamp in the same day.

After using this integration a lot more I've noticed the timestamps, even when the end-time is set, are still 1 hour behind when seen in RT. Note that we are currently in CET, but on the 26.03.2023 it will be CEST.
Skjermbilde RT
Skjermbilde Argus

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.