Exemplo n.º 1
0
def construct_msg(session, bodysize, timezone):
    statusl = ['OK', 'WARNING', 'MISSING', 'CRITICAL', 'UNKNOWN', 'DOWNTIME']

    try:
        msg = Message()
        msg.header = dict()
        msg.body = str()

        msg.header.update({'service': generator.rndb64(10)})
        msg.header.update({'hostname': generator.rndb64(10)})
        msg.header.update({'metric': generator.rndb64(10)})
        msg.header.update({'monitoring_host': generator.rndb64(10)})
        msg.header.update({
            'timestamp':
            str(
                datetime.datetime.now(timezone).strftime('%Y-%m-%dT%H:%M:%SZ'))
        })
        msg.header.update({'status': random.choice(statusl)})

        msg.body += 'summary: %s\n' % generator.rndb64(20)
        msg.body += 'message: %s\n' % generator.rndb64(bodysize)
        msg.body += 'vofqan: %s\n' % generator.rndb64(10)
        if session:
            msg.body += 'actual_data: *** SESSION %s *** %s\n' % (
                session, generator.rndb64(10))
        else:
            msg.body += 'actual_data: %s\n' % generator.rndb64(10)
        msg.body += 'voname: %s\n' % generator.rndb64(3)
        msg.body += 'roc: %s\n' % generator.rndb64(3)

    except MessageError as e:
        sys.stderr.write('Error constructing message - %s\n', repr(e))

    else:
        return msg
Exemplo n.º 2
0
 def test_full_chain(self):
     """ Test kombu full chain. """
     print("checking kombu full chain")
     try:
         import kombu
     except ImportError:
         print("kombu is not available, skipping it")
         return
     mq1_path = self.path + "/mq1"
     mq2_path = self.path + "/mq2"
     mq1 = DQS(path=mq1_path)
     count = 10
     dest = "/queue/test%s" % (rndstr(10), )
     bodies = list()
     for i in range(count):
         body = "hello world %s" % (i, )
         bodies.append(body)
         msg = Message(body=body)
         msg.header = {"destination": dest}
         mq1.add_message(msg)
     self.assertEqual(count, mq1.count())
     cmd1 = "python bin/amqpclt --incoming-queue path=%s" \
            " --outgoing-broker-uri %s " \
            " --outgoing-broker-module kombu " \
            " --outgoing-broker-auth plain,name=guest,pass=guest" \
            " --remove --loglevel debug" \
            % (mq1_path, self.broker)
     (ret, out, err) = proc.timed_process(cmd1.split())
     self.assertEqual(0, ret, "out: %s\nerr: %s" % (out, err))
     cmd2 = "python bin/amqpclt --incoming-broker-uri %s" \
            " --incoming-broker-module kombu" \
            " --incoming-broker-auth plain,name=guest,pass=guest" \
            " --subscribe destination=%s" \
            " --outgoing-queue path=%s --count %d --reliable " \
            "--loglevel debug" \
            % (self.broker, dest, mq2_path, count)
     (ret, out, err) = proc.timed_process(cmd2.split())
     self.assertEqual(0, ret, "out: %s\nerr: %s" % (out, err))
     mq2 = DQS(path=mq2_path)
     for i in mq2:
         if mq2.lock(i):
             bodies.remove(mq2.get_message(i).body)
     self.assertEqual(count, mq2.count())
     self.assertEqual(0, len(bodies))
     self.assertEqual(0, mq1.count())
     print("checking kombu fullchain OK")
Exemplo n.º 3
0
 def test_full_chain(self):
     """ Test kombu full chain. """
     print("checking kombu full chain")
     try:
         import kombu
     except ImportError:
         print("kombu is not available, skipping it")
         return
     mq1_path = self.path + "/mq1"
     mq2_path = self.path + "/mq2"
     mq1 = DQS(path=mq1_path)
     count = 10
     dest = "/queue/test%s" % (rndstr(10), )
     bodies = list()
     for i in range(count):
         body = "hello world %s" % (i, )
         bodies.append(body)
         msg = Message(body=body)
         msg.header = {"destination": dest}
         mq1.add_message(msg)
     self.assertEqual(count, mq1.count())
     cmd1 = "python bin/amqpclt --incoming-queue path=%s" \
            " --outgoing-broker-uri %s " \
            " --outgoing-broker-module kombu " \
            " --outgoing-broker-auth plain,name=guest,pass=guest" \
            " --remove --loglevel debug" \
            % (mq1_path, self.broker)
     (ret, out, err) = proc.timed_process(cmd1.split())
     self.assertEqual(0, ret, "out: %s\nerr: %s" % (out, err))
     cmd2 = "python bin/amqpclt --incoming-broker-uri %s" \
            " --incoming-broker-module kombu" \
            " --incoming-broker-auth plain,name=guest,pass=guest" \
            " --subscribe destination=%s" \
            " --outgoing-queue path=%s --count %d --reliable " \
            "--loglevel debug" \
            % (self.broker, dest, mq2_path, count)
     (ret, out, err) = proc.timed_process(cmd2.split())
     self.assertEqual(0, ret, "out: %s\nerr: %s" % (out, err))
     mq2 = DQS(path=mq2_path)
     for i in mq2:
         if mq2.lock(i):
             bodies.remove(mq2.get_message(i).body)
     self.assertEqual(count, mq2.count())
     self.assertEqual(0, len(bodies))
     self.assertEqual(0, mq1.count())
     print("checking kombu fullchain OK")
Exemplo n.º 4
0
def build_msg(args, *headers):
    msg = Message()
    msg.header = dict()
    msg.body = str()

    timestamp, service, hostname, testname, status, nagioshost = headers

    msg.header.update({'execution_time': timestamp})
    msg.header.update({'service_flavour': service})
    msg.header.update({'node_name': hostname})
    msg.header.update({'test_name': testname})
    msg.header.update({'status': status})

    for bs in ['details', 'vo', 'site', 'roc', 'urlhistory', 'urlhelp']:
        code = "msg.body += '%s: ' + args.%s + '\\n' if args.%s else ''" % (
            bs, bs, bs)
        exec(code)

    msg.text = True
    return msg
Exemplo n.º 5
0
def construct_msg(session, bodysize, timezone, schemapath):
    statusl = ['OK', 'WARNING', 'MISSING', 'CRITICAL', 'UNKNOWN', 'DOWNTIME']

    try:
        msg = Message()
        msg.header = dict()
        msg.body = str()

        if session:
            msg.header.update(
                {'*** SESSION ***': '*** {0} ***'.format(session)})
        msg.header.update({'service': generator.rndb64(10)})
        msg.header.update({'hostname': generator.rndb64(10)})
        msg.header.update({'metric': generator.rndb64(10)})
        msg.header.update({'monitoring_host': generator.rndb64(10)})
        msg.header.update({
            'timestamp':
            str(
                datetime.datetime.now(timezone).strftime('%Y-%m-%dT%H:%M:%SZ'))
        })
        msg.header.update({'status': random.choice(statusl)})

        msg.body += 'summary: %s\n' % generator.rndb64(20)
        msg.body += 'message: %s\n' % generator.rndb64(bodysize)
        msg.body += 'vofqan: %s\n' % generator.rndb64(10)
        msg.body += 'actual_data: %s\n' % generator.rndb64(10)
        msg.body += 'voname: %s\n' % generator.rndb64(3)
        msg.body += 'roc: %s\n' % generator.rndb64(3)

        plainmsg = dict()
        plainmsg.update(msg.header)
        plainmsg.update(body2dict(msg.body))
        plainmsg.update(tags=tag2dict(msg.body))

        return avro_serialize(plainmsg, schemapath)

    except MessageError as e:
        sys.stderr.write('Error constructing message - %s\n', repr(e))

    else:
        return msg
def build_msg(args, *headers):
    msg = Message()
    msg.header = dict()
    msg.body = str()

    timestamp, service, hostname, metric, status, nagioshost = headers

    msg.header.update({'timestamp': timestamp})
    msg.header.update({'service': service})
    msg.header.update({'hostname': hostname})
    msg.header.update({'metric': metric})
    msg.header.update({'status': status})
    msg.header.update({'monitoring_host': nagioshost})

    for bs in [
            'summary', 'message', 'vofqan', 'voname', 'roc', 'actual_data',
            'site'
    ]:
        code = "msg.body += '%s: ' + args.%s + '\\n' if args.%s else ''" % (
            bs, bs, bs)
        exec(code)

    msg.text = True
    return msg