Esempio n. 1
0
def logout():
    set_logging('debug')
    logger = logging.getLogger('rtkit')

    my_config = DITICConfig()
    system = my_config.get_system()

    resource = RTResource('http://localhost/rt/REST/1.0/', system['username'],
                          system['password'], CookieAuthenticator)

    #create a ticket
    content = {'content': {}}

    try:
        response = resource.post(
            path='logout/',
            payload=content,
        )
        logger.info(response.parsed)

    except RTResourceError as e:
        logger.error(e.response.status_int)
        logger.error(e.response.status)
        logger.error(e.response.parsed)
    redirect("/")
Esempio n. 2
0
def create_ticket(mispid, subject):
    set_logging('error')
    logger = logging.getLogger('rtkit')
    resource = RTResource(rt_url, rt_user, rt_pass, CookieAuthenticator)

    emails = "*****@*****.**"

    subject = "%s - takedown" % (subject)
    body = "Automatically imported via MISP # %s" % (mispid)
    content = {
        'content': {
            'queue': 3,
            'requestor': emails,
            'subject': urllib.quote(subject),
            'text': body,
        }
    }

    try:
        response = resource.post(
            path='ticket/new',
            payload=content,
        )
        logger.info(response.parsed)
        for t in response.parsed:
            ticketid = t[0][1]
        return ticketid.replace('ticket/', '')
    except RTResourceError as e:
        logger.error(e.response.status_int)
        logger.error(e.response.status)
        logger.error(e.response.parsed)
def __callback(ch, method, properties, body):
    
    '''
        This is the callback function that is called when a message is delivered to the message queue
        IT SHOULD NOT BE CALLED DIRECTLY
        
        In this implementation we are forwarding these messages into the RT queue specified in the configuration file
    
    '''
    from rtkit.resource import RTResource
    from rtkit.authenticators import CookieAuthenticator
    from rtkit.errors import RTResourceError
    
    from rtkit import set_logging 
    import logging
    set_logging('error')
    logger = logging.getLogger('rtkit')
    
    auth = CookieAuthenticator(configInfo['RTUser'], configInfo['RTUserPass'])
    resource = RTResource('%s/REST/1.0/' % (configInfo['RTHost'],), auth)
    
    
    content = {'content':   {
                                'Queue': configInfo['RTQueueId'],
                                'Subject' : body,
                            }
               }
    try:
        response = resource.post(path='ticket/new', payload=content,)
        logger.info(response.parsed)
    except RTResourceError as e:
        logger.error(e.response.status_int)
        logger.error(e.response.status)
        logger.error(e.response.parsed)
Esempio n. 4
0
def modifyTicket(ticketID):
    global emailGlobal
    dic = {"email": emailGlobal}
    lst = []

    set_logging('debug')
    logger = logging.getLogger('rtkit')

    my_config = DITICConfig()
    system = my_config.get_system()

    resource = RTResource('http://localhost/rt/REST/1.0/', system['username'],
                          system['password'], CookieAuthenticator)

    try:
        response = resource.get(path='ticket/' + ticketID)
        for r in response.parsed:
            for t in r:
                logger.info(t)
                lst.append(t)

    except RTResourceError as e:
        logger.error(e.response.status_int)
        logger.error(e.response.status)
        logger.error(e.response.parsed)

    lst = dict(lst)

    return template("ticketDetails", lst=lst, ticketID=ticketID, dic=dic)
 def __init__(self, userName, password, rt_api_url):
     '''
     Constructor
     '''
     from rtkit import set_logging
     import logging
     set_logging('debug')
     logger = logging.getLogger('rtkit')
     #resource = RTResource('http://<HOST>/REST/1.0/', '<USER>', '<PWD>', BasicAuthenticator)
     resource = RTResource(rt_api_url, userName, password, BasicAuthenticator)
Esempio n. 6
0
def createTicket():
    global emailGlobal

    priority = ''

    priority = int(request.forms.get('priority'))

    if priority >= 200:
        setUrgent = 'yes'
    else:
        setUrgent = ''

    set_logging('debug')
    logger = logging.getLogger('rtkit')

    my_config = DITICConfig()
    system = my_config.get_system()

    resource = RTResource('http://localhost/rt/REST/1.0/', system['username'],
                          system['password'], CookieAuthenticator)

    #create a ticket
    content = {
        'content': {
            'Queue': request.forms.get(
                "queue"
            ),  #General - unassigned is the name of the desired queue
            'Requestors': emailGlobal,
            'Subject':
            request.forms.get("subject"),  #text to go into subject field
            'Text': request.forms.get("content"),
            'Priority': request.forms.get('priority'),
            'CF.{servico}': request.forms.get("servico"),
            'CF.{IS - Informatica e Sistemas}':
            request.forms.get("inforsistemas"),
            'CF.{DITIC - Interrupted}': '',
            'CF.{DITIC - Urgent}': setUrgent,
        }
    }

    try:
        response = resource.post(
            path='ticket/new',
            payload=content,
        )
        logger.info(response.parsed)

    except RTResourceError as e:
        logger.error(e.response.status_int)
        logger.error(e.response.status)
        logger.error(e.response.parsed)
Esempio n. 7
0
def updateTicket(ticketID):
    global emailGlobal

    priority = int(request.forms.get('priority'))

    if priority > 255:
        priority = 255

    if priority >= 200:
        setUrgent = 'yes'
    else:
        setUrgent = ''

    set_logging('debug')
    logger = logging.getLogger('rtkit')

    my_config = DITICConfig()
    system = my_config.get_system()

    resource = RTResource('http://localhost/rt/REST/1.0/', system['username'],
                          system['password'], CookieAuthenticator)

    #create a ticket
    content = {
        'content': {
            'Priority': str(priority),
            'cf.{ditic - urgent}': setUrgent,
        }
    }

    try:
        response = resource.post(
            path='ticket/' + ticketID,
            payload=content,
        )
        logger.info(response.parsed)

    except RTResourceError as e:
        logger.error(e.response.status_int)
        logger.error(e.response.status)
        logger.error(e.response.parsed)
def __callback(ch, method, properties, body):
    '''
        This is the callback function that is called when a message is delivered to the message queue
        IT SHOULD NOT BE CALLED DIRECTLY
        
        In this implementation we are forwarding these messages into the RT queue specified in the configuration file
    
    '''
    from rtkit.resource import RTResource
    from rtkit.authenticators import CookieAuthenticator
    from rtkit.errors import RTResourceError

    from rtkit import set_logging
    import logging
    set_logging('error')
    logger = logging.getLogger('rtkit')

    auth = CookieAuthenticator(configInfo['RTUser'], configInfo['RTUserPass'])
    resource = RTResource('%s/REST/1.0/' % (configInfo['RTHost'], ), auth)

    content = {
        'content': {
            'Queue': configInfo['RTQueueId'],
            'Subject': body,
        }
    }
    try:
        response = resource.post(
            path='ticket/new',
            payload=content,
        )
        logger.info(response.parsed)
    except RTResourceError as e:
        logger.error(e.response.status_int)
        logger.error(e.response.status)
        logger.error(e.response.parsed)
Esempio n. 9
0
def addComment(ticketID):
    set_logging('debug')
    logger = logging.getLogger('rtkit')

    my_config = DITICConfig()
    system = my_config.get_system()

    resource = RTResource('http://localhost/rt/REST/1.0/', system['username'],
                          system['password'], CookieAuthenticator)

    try:
        params = {
            'content': {
                'Action': 'comment',
                'Text': request.forms.get("content"),
            },
        }

        params2 = {
            'content': {
                'status': 'resolved',
            }
        }
        response = resource.post(
            path='ticket/' + ticketID + '/comment',
            payload=params,
        )
        response = resource.post(path='ticket/' + ticketID, payload=params2)
        for r in response.parsed:
            for t in r:
                logger.info(t)

    except RTResourceError as e:
        logger.error(e.response.status_int)
        logger.error(e.response.status)
        logger.error(e.response.parsed)
        global min_size
        request = urllib2.Request(resource)
        request.add_header('User-agent', ua)
        response = urllib2.urlopen(request)
        size = len(response.read())
        if int(size) > min_size:
            return True, size
        else:
            return False, size
    except Exception as e:
        print e
        return False, -1


# RT
set_logging('error')
logger = logging.getLogger('rtkit')
resource = RTResource(rt_url, rt_user, rt_pass, CookieAuthenticator)

# Sphinx
client = sphinxapi.SphinxClient()
client.SetServer(sphinx_server, sphinx_port)
client.SetMatchMode(2)


def is_ticket_open(id):
    status = False
    try:
        ticket = "ticket/%s" % id
        response = resource.get(path=ticket)
        for r in response.parsed:
Esempio n. 11
0
from rtkit.resource import RTResource
from rtkit.authenticators import BasicAuthenticator
from rtkit.authenticators import CookieAuthenticator
from rtkit.errors import RTResourceError
from rtkit import set_logging

import logging

set_logging('debug')
logger = logging.getLogger('rtkit')

DEBUGGING = False


def read_credentials(credentials_file):
    with open(credentials_file) as f:
        content = f.readlines()
    return content[0].strip(), content[1].strip()


username, password = read_credentials("credentials.txt")
resource = RTResource('https://help.rice.edu/REST/1.0/', username, password,
                      CookieAuthenticator)


def submit_ticket(queue, status, requestor, subject, text):
    global resource, DEBUGGING
    content = {
        'content': {
            'Queue': queue,
            'Status': status,
Esempio n. 12
0
import sys
import logging

from rtkit.resource import RTResource
from rtkit.authenticators import BasicAuthenticator
from rtkit.errors import RTResourceError
from rtkit import set_logging

set_logging("debug")
logger = logging.getLogger("rtkit")

resource = RTResource("http://rt.cla.umn.edu/REST/1.0/", sys.argv[1], sys.argv[2], BasicAuthenticator)

try:
    response = resource.get(
        path="search/ticket?query=Owner=%s&user=%s&pass=%s" % (sys.argv[1], sys.argv[1], sys.argv[2])
    )
    for r in response.parsed:
        for t in r:
            logger.info(t)

except RTResourceError as e:
    logger.error(e.response.status_int)
    logger.error(e.response.status)
    logger.error(e.response.parsed)
Esempio n. 13
0
def check_url_create_investigation(incident, template, url, override,
                                   onlinecheck):
    mypath = os.path.dirname(os.path.realpath(sys.argv[0]))
    template = os.path.join(mypath, template)
    global ua
    global min_size
    global override_email
    global event_tag
    # RT
    set_logging('error')
    logger = logging.getLogger('rtkit')
    resource = RTResource(rt_url, rt_user, rt_pass, CookieAuthenticator)
    open_tickets = open_tickets_for_url(url)
    if open_tickets > 0:
        return "URL %s was already handled in ticket %s" % (url, open_tickets)
    if onlinecheck is True:
        online, size = is_online(url)
        if not online:
            return "URL %s is offline (size: %s)" % (url, size)
    with nostdout():
        emails, text, asn = urlabuse.run_lookup(url)
    text = defang(urllib.quote(text))
    d = {'details': text}

    try:
        f = open(template)
        subject = f.readline().rstrip()
        templatecontent = Template(f.read())
        body = templatecontent.substitute(d)
    except:
        print "Couldn't open template file (%s)" % template
        sys.exit(1)
    f.close()
    if event_tag == "tlp:green":
        subject = "[TLP:GREEN] " + subject
    # Override emails destinations for test
    if override is True:
        emails = override_email

    asn_out = []
    for x in asn:
        asn_out.append(",".join(x))
    asn_out = "|".join(asn_out)
    subject = "%s (%s)" % (subject, asn_out)
    content = {
        'content': {
            'queue': 5,
            'requestor': emails,
            'subject': urllib.quote(subject),
            'text': body,
        }
    }

    if debug:
        sys.exit(42)

    try:
        response = resource.post(
            path='ticket/new',
            payload=content,
        )
        logger.info(response.parsed)
        for t in response.parsed:
            ticketid = t[0][1]
    except RTResourceError as e:
        logger.error(e.response.status_int)
        logger.error(e.response.status)
        logger.error(e.response.parsed)

    #update ticket link
    content = {
        'content': {
            'memberof': incident,
        }
    }
    try:
        ticketpath = "%s/links" % ticketid
        response = resource.post(
            path=ticketpath,
            payload=content,
        )
        logger.info(response.parsed)
        return "Investigation created for URL %s" % (url)
    except RTResourceError as e:
        logger.error(e.response.status_int)
        logger.error(e.response.status)
        logger.error(e.repoinse.parsed)
Esempio n. 14
0
from rtkit.resource import RTResource
from rtkit.authenticators import KerberosAuthenticator
from rtkit.errors import RTResourceError
from rtkit import set_logging
import logging
import sys

def test(url):
    resource = RTResource(url, None, None, KerberosAuthenticator)
    try:
        response = resource.get(path='ticket/1')
        for r in response.parsed:
            for t in r:
                logger.info(t)
    except RTResourceError as e:
        logger.error(e.response.status_int)
        logger.error(e.response.status)
        logger.error(e.response.parsed)


if __name__ == "__main__":
    set_logging('debug')
    logger = logging.getLogger('rtkit')
    try:
        url = sys.argv[1]
    except: raise Exception("Run %s <url>" % sys.argv[0])
    test(url)
Esempio n. 15
0
import yaml
import os
import re
import sys
from resource import RTResource
from authenticators import CookieAuthenticator
from errors import RTResourceError

from rtkit import set_logging
import logging
set_logging('debug' if '-v' in sys.argv else 'info')
logger = logging.getLogger('rtkit')

import getpass

u = getpass.getpass(prompt='username? ')
print 'You entered:', u
p = getpass.getpass()

resource = RTResource('https://rt.wikimedia.org/REST/1.0/', u, p, CookieAuthenticator)
TICKET = sys.argv[1]
yaml_file = 'data.yaml'

try:
    tinfo = resource.get(path="ticket/%s" % (TICKET,))
    attachments = resource.get(path="ticket/%s/attachments/" % (TICKET,))
    history = resource.get(path="ticket/%s/history?format=l" % (TICKET,))

    #we get back freeform text and create a dict
    dtinfo = {}
    for cv in tinfo.strip().splitlines():
Esempio n. 16
0
from rtkit.errors import RTResourceError
from rtkit import set_logging
from jira.client import JIRA
from jira.exceptions import JIRAError
from titlecase import titlecase
import time
import os
import pprint
import re
import sys
import logging
import ConfigParser
import syslog

# Initialize RT library logging
set_logging('error')
rt_logger = logging.getLogger('rtkit')

# Initialize app-level logging
logger = logging.getLogger('rt2jira')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(logging.Formatter('%(asctime)s %(name)s[%(process)s]: [%(levelname)s] - %(message)s', "%b %m %H:%M:%S"))
logger.addHandler(ch)

# Initialize factories
pp = pprint.PrettyPrinter(indent=4)

# Define helper functions
def rt_format_ticket_time(t):