Exemplo n.º 1
0
 def test_error_frame_after_connect_raises_StompProtocolError(self):
     stomp = Stomp('localhost', 61613)
     stomp._socketConnect = Mock()
     stomp.receiveFrame = Mock()
     stomp.receiveFrame.return_value = {'cmd': 'ERROR', 'headers': {}, 'body': 'fake error'}
     stomp.socket = Mock()
     self.assertRaises(StompProtocolError, lambda: stomp.connect())
     self.assertEquals(stomp.receiveFrame.call_count, 1, "receiveFrame not called")
Exemplo n.º 2
0
 def test_ack_writes_correct_frame(self):
     id = '12345'
     stomp = Stomp('localhost', 61613)
     stomp._checkConnected = Mock()
     stomp._write = Mock()
     stomp.ack({'cmd': 'MESSAGE', 'headers': {'message-id': id}, 'body': 'blah'})
     args,kargs = stomp._write.call_args
     sentFrame = self.parseFrame(args[0])
     self.assertEquals({'cmd': 'ACK',
                        'headers': {'message-id': id,
                                   },
                        'body': ''}, sentFrame)
Exemplo n.º 3
0
 def test_send_writes_correct_frame(self):
     dest = '/queue/foo'
     msg = 'test message'
     headers = {'foo': 'bar', 'fuzz': 'ball'}
     stomp = Stomp('localhost', 61613)
     stomp._checkConnected = Mock()
     stomp._write = Mock()
     stomp.send(dest, msg, headers)
     args,kargs = stomp._write.call_args
     sentFrame = self.parseFrame(args[0])
     self.assertEquals({'cmd': 'SEND',
                        'headers': {'destination': dest,
                                    'foo': 'bar',
                                    'fuzz': 'ball',
                                   },
                        'body': msg}, sentFrame)
Exemplo n.º 4
0
 def test_subscribe_writes_correct_frame(self):
     dest = '/queue/foo'
     headers = {'foo': 'bar', 'fuzz': 'ball'}
     stomp = Stomp('localhost', 61613)
     stomp._checkConnected = Mock()
     stomp._write = Mock()
     stomp.subscribe(dest, headers)
     args,kargs = stomp._write.call_args
     sentFrame = self.parseFrame(args[0])
     self.assertEquals({'cmd': 'SUBSCRIBE',
                        'headers': {'destination': dest,
                                    'ack': 'auto',
                                    'activemq.prefetchSize': '1',
                                    'foo': 'bar',
                                    'fuzz': 'ball',
                                   },
                        'body': ''}, sentFrame)
Exemplo n.º 5
0
 def test_connect_writes_correct_frame(self):
     login = '******'
     passcode = 'george'
     stomp = Stomp('localhost', 61613)
     stomp._socketConnect = Mock()
     stomp.receiveFrame = Mock()
     stomp.receiveFrame.return_value = {'cmd': 'CONNECTED', 'headers': {}, 'body': ''}
     stomp.socket = Mock()
     stomp.connect(login=login,passcode=passcode)
     args,kargs = stomp.socket.sendall.call_args
     sentFrame = self.parseFrame(args[0])
     self.assertEquals({'cmd': 'CONNECT',
                        'headers': {'login': login,
                                    'passcode': passcode,
                                   },
                        'body': ''}, sentFrame)
 def cleanQueue(self, queue):
     stomp = Stomp(HOST, PORT)
     stomp.connect()
     stomp.subscribe(queue, {"ack": "client"})
     while stomp.canRead(1):
         frame = stomp.receiveFrame()
         stomp.ack(frame)
         print "Dequeued old message: %s" % frame
     stomp.disconnect()
Exemplo n.º 7
0
def get_stomp_connection():
    stomp_connection = Stomp(sett.STOMP_HOST, sett.STOMP_PORT)
    stomp_connection.connect(sett.STOMP_USERNAME, sett.STOMP_PASSWORD)
    return stomp_connection
 def cleanQueue(self, queue):
     stomp = Stomp('localhost', 61613)
     stomp.connect()
     stomp.subscribe(queue, {'ack': 'client'})
     while stomp.canRead(1):
         frame = stomp.receiveFrame()
         stomp.ack(frame)
         print "Dequeued old message: %s" % frame
     stomp.disconnect()        
def supportsClientIndividual():
    supported = False
    queue = '/queue/testClientAckMode'
    stomp = Stomp('localhost', 61613)
    stomp.connect()
    stomp.send(queue, 'test')
    stomp.subscribe(queue, {'ack': 'client-individual'})
    frame = stomp.receiveFrame()
    #Do not ACK.  If client-individual mode is supported, the messages will still be on the broker
    stomp.disconnect()
    stomp.connect()
    stomp.subscribe(queue, {'ack': 'client'})
    if stomp.canRead(1):
        frame = stomp.receiveFrame()
        stomp.ack(frame)
        supported = True
    stomp.disconnect()
    return supported
Exemplo n.º 10
0
"""
Copyright 2011 Mozes, Inc.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""
from stompest.simple import Stomp

QUEUE = '/queue/simpleTest'

stomp = Stomp('localhost', 61613)
stomp.connect()
stomp.subscribe(QUEUE, {'ack': 'client'})

while(True):
    frame = stomp.receiveFrame()
    print "Got message frame: %s" % frame
    stomp.ack(frame)
    
stomp.disconnect()
Exemplo n.º 11
0
 def test_connect_raises_exception_for_bad_host(self):
     stomp = Stomp('nosuchhost', 2345)
     self.assertRaises(Exception, lambda: stomp.connect())
Exemplo n.º 12
0
 def test_disconnect_raises_exception_before_connect(self):
     stomp = Stomp('localhost', 61613)
     self.assertRaises(Exception, lambda: stomp.disconnect())
Exemplo n.º 13
0
 def test_subscribe_raises_exception_before_connect(self):
     stomp = Stomp('localhost', 61613)
     self.assertRaises(Exception, lambda: stomp.subscribe('/queue/foo'))
Exemplo n.º 14
0
 def test_send_raises_exception_before_connect(self):
     stomp = Stomp('localhost', 61613)
     self.assertRaises(Exception, lambda: stomp.send('/queue/foo', 'test message'))
Exemplo n.º 15
0
def main():

    loglevel = logging.INFO
    logging.basicConfig(level=loglevel, format="%(asctime)s alert-aws[%(process)d] %(levelname)s Thread-%(thread)d - %(message)s", filename=LOGFILE, filemode='a')

    print '%-10s %11s %20s %25s %25s' % ('ec2-zone', 'instance-id', 'state (code)', 'reachability', 'instance-status')
    print '%s %s %s %s %s' % ('-'*10, '-'*11, '-'*20, '-'*25, '-'*25)
    regions = boto.ec2.regions()
    for r in regions:
        conn = r.connect()
        stats = conn.get_all_instance_status()
        for s in stats:
            print '%10s %11s %20s %25s %25s' % (s.zone, s.id, s.state_name+' ('+str(s.state_code)+')', s.system_status, s.instance_status)

    sys.exit()


    regions = boto.ec2.regions()
    eu = regions[0]
    conn = eu.connect()
    stats = conn.get_all_instance_status()

    for s in stats:
        print 'instance %s status %s' % (s.id, s.state_name)

    sys.exit()


    alertid = str(uuid.uuid4()) # random UUID

    headers = dict()
    headers['type'] = "text"
    headers['correlation-id'] = alertid

    alert = dict()
    alert['id']          = alertid
    alert['resource']    = options.resource
    alert['event']       = options.event
    alert['group']       = options.group
    alert['value']       = options.value
    alert['severity']    = options.severity.upper()
    if options.previousSeverity:
        alert['previousSeverity']    = options.previousSeverity.upper()
    alert['environment'] = options.environment.upper()
    alert['service']     = options.service
    alert['text']        = options.text
    alert['type']        = 'exceptionAlert'
    alert['tags']        = options.tags
    alert['summary']     = '%s - %s %s is %s on %s %s' % (options.environment, options.severity, options.event, options.value, options.service, os.uname()[1])
    alert['createTime']  = datetime.datetime.now().isoformat()+'Z'
    alert['origin']      = 'alert-cli/%s' % os.uname()[1]
    alert['repeat']      = options.repeat

    logging.info('ALERT: %s', json.dumps(alert))

    if (not options.dry_run):
        broker, port = BROKER.split(':')
        stomp = Stomp(broker, int(port))
        try:
            stomp.connect()
        except Exception, e:
            print >>sys.stderr, "ERROR: Could not connect to broker %s - %s" % (BROKER, e)
            logging.error('ERROR: Could not connect to to broker %s - %s', BROKER, e)
            sys.exit(1)
        try:
            stomp.send(QUEUE, json.dumps(alert), headers)
        except Exception, e:
            print >>sys.stderr, "ERROR: Failed to send alert to broker %s - %s " % (BROKER, e)
            logging.error('ERROR: Failed to send alert to broker %s - %s', BROKER, e)
            sys.exit(1)
Exemplo n.º 16
0
 def setUp(self):
     stomp = Stomp('localhost', 61613)
     stomp.connect()
     stomp.subscribe(self.DEST, {'ack': 'client'})
     while (stomp.canRead(1)):
         stomp.ack(stomp.receiveFrame())
Exemplo n.º 17
0
 def test_integration(self):
     stomp = Stomp('localhost', 61613)
     stomp.connect()
     stomp.send(self.DEST, 'test message1')
     stomp.send(self.DEST, 'test message2')
     self.assertFalse(stomp.canRead(1))
     stomp.subscribe(self.DEST, {'ack': 'client'})
     self.assertTrue(stomp.canRead(1))
     frame = stomp.receiveFrame()
     stomp.ack(frame)
     self.assertTrue(stomp.canRead(1))
     frame = stomp.receiveFrame()
     stomp.ack(frame)
     self.assertFalse(stomp.canRead(1))
     stomp.disconnect()
Exemplo n.º 18
0
"""
Copyright 2011 Mozes, Inc.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
"""
from stompest.simple import Stomp

QUEUE = '/queue/simpleTest'

stomp = Stomp('localhost', 61613)
stomp.connect()
stomp.send(QUEUE, 'test message1')
stomp.send(QUEUE, 'test message2')
stomp.disconnect()