Esempio n. 1
0
def main():
    ''' main program loop '''
    conn = symphony.Config('example-bot.cfg')
    # connect to pod
    agent, pod, symphony_sid = conn.connect()
    agent.test_echo('test')
    # main loop
    msgFormat = 'MESSAGEML'
    message = '<messageML> hello world. </messageML>'
    # send message
    agent.send_message(symphony_sid, msgFormat, message)
def main():
    ''' main program loop '''
    conn = symphony.Config('es-bot.cfg')
    # connect to pod
    try:
        agent, pod, symphony_sid, ifttt_webhook = conn.connect()
        print 'connected: %s' % symphony_sid
        print agent
        print pod
        #print session_token
    except Exception as err:
        #print 'failed to connect!'
        print err

    statcode, id = agent.create_datafeed()
    print('create datafeed status code: ')
    print(statcode)
    print('create datafeed id')
    print(id)
    while 1:
        statcode, resp = agent.read_datafeed(id)
        print('read datafeed status code: ')
        print(statcode)
        print('read datafeed response')
        print(resp)
        #parsed_json = json.loads(resp)
        if len(resp) > 0:
            echomsg = resp[0].get('message')
            Userid = resp[0].get('fromUserId')

            print(echomsg)
            echomsgsplit1 = echomsg.split('<messageML>')
            if echomsgsplit1[1].startswith('<mention uid="USER_ID"/>'):
                msg_actual = echomsgsplit1[1].lstrip(
                    '<mention uid="USER_ID"/> ')
                msg_actual = msg_actual.rstrip('</messageML>')
                print(msg_actual)
                r = requests.post(ifttt_webhook, data={"value1": msg_actual})

                msgFormat = 'MESSAGEML'

                message = '<messageML>Nobody summons Megatron!</messageML>'
                # send message
                try:
                    status_code, retstring = agent.send_message(
                        symphony_sid, msgFormat, message)
                    print "%s: %s" % (status_code, retstring)
                except:
                    print(retstring)
Esempio n. 3
0
def main():
    ''' main program loop '''
    conn = symphony.Config('es-bot.cfg')
    # connect to pod
    try:
        agent, pod, symphony_sid = conn.connect()
        print ('connected: %s' % symphony_sid)
    except Exception as error_str:
        print (error_str)
    # main loop
    msgFormat = 'MESSAGEML'
    message = '<messageML> hello world </messageML>'
    # send message
    try:
        status_code, retstring = agent.send_message(symphony_sid, msgFormat, message)
        print ("%s: %s") % (status_code, retstring)
    except Exception as pork:
        print(pork)
Esempio n. 4
0
def main():
    ''' main program loop '''
    conn = symphony.Config('/etc/es-bot/es-bot.cfg')
    # connect to pod
    try:
        agent, pod, symphony_sid = conn.connect()
        print('connected: %s' % (symphony_sid))
    except Exception as err:
        print('failed to connect!: %s' % (err))
    # main loop
    msgFormat = 'MESSAGEML'
    message = '<messageML> hello world. </messageML>'
    # send message
    try:
        status_code, retstring = agent.send_message(symphony_sid, msgFormat,
                                                    message)
        print("%s: %s" % (status_code, retstring))
    except Exception as err:
        print(retstring, err)
Esempio n. 5
0
def main():
    ''' main program loop '''
    # CLI flag parsing
    parser = argparse.ArgumentParser(description='metronome bot')
    # specify config file
    parser.add_argument(
        '-c', '--config', nargs='?',
        help='specify path to config file',
        default='/etc/metronome/metronome.cfg'
    )
    # specify logging file
    parser.add_argument(
        '-l', '--log', nargs='?',
        help='specify path to log file',
        default='/var/log/metronome/metronome.log'
    )
    # specify debug logging
    parser.add_argument(
        '-d', '--debug',
        action='store_true',
        help='debug logging'
    )
    # specify cache counter file
    parser.add_argument(
        '--counter', nargs='?',
        help='specify path to cache counter',
        default='/var/cache/metronome/counter'
    )
    # parse
    try:
        args = parser.parse_args()
    except Exception as err:
        print('failed to parse arguments: %s' % (err))
        sys.exit(1)
    # silence INFO alerts from requests module
    logging.getLogger("requests").setLevel(logging.WARNING)
    logging.getLogger("urllib3").setLevel(logging.WARNING)
    # toggle on debug flag
    if args.debug is False:
        logging.basicConfig(filename=args.log, level=logging.INFO, format='%(asctime)s %(message)s')
    else:
        logging.basicConfig(filename=args.log, level=logging.DEBUG, format='%(asctime)s %(message)s')

    # run configuration
    conn = symphony.Config(str(args.config))
    # connect to pod
    try:
        agent, pod, symphony_sid = conn.connect()
    except Exception as err:
        print('failed to connect to symphony: %s' % (err))
        sys.exit(1)
    # get datafeed
    try:
        datafeed_id = agent.create_datafeed()
        print(datafeed_id)
    except Exception as err:
        print('failed to allocate datafeed id: %s' % (err))
        sys.exit(1)
    # main loop
    while True:
        # this polls and returns a list of alert ids
        try:
            # increment counter and initiate sleep cycle
            inc_counter()
            time.sleep(5)
            # accept pending connection requests
            connection_resp = pod.list_connections()
            for request in connection_resp:
                if request['status'] == 'PENDING_INCOMING':
                    pod.accept_connection(request['userId'])
            # perform user search globally
            search_filter = {"company": "Symphony Corporate"}
            local = 'false'
            search_resp, search_ret = pod.search_user('maximilian', search_filter, local)
            search_data = json.loads(search_ret)
            searched_count = search_data['count']
            searched_id = search_data['users'][0]['id']
            searched_email = search_data['users'][0]['emailAddress']
            searched_name = search_data['users'][0]['displayName']
            search_stats = '%s results found, showing first : (%s) %s - %s'\
                           % (searched_count, searched_id, searched_name, searched_email)
            # check counter
            count = get_counter()
            # build polling message
            msgFormat = 'MESSAGEML'
            message = '<messageML><b>%s ( %s )</b> <i>%s</i> \
                       %s - search maximilian - <b> %s </b> : <i> %s </i> </messageML>'\
                      % ('tick',
                         str(count),
                         datetime.datetime.now(),
                         uuid.uuid4(),
                         str(search_resp),
                         search_stats)
            # send message
            retstring = agent.send_message(symphony_sid, msgFormat, message)
            print(retstring)
        # if main loop fails... try to reconnect
        except Exception as err:
            try:
                datafeed_id = agent.create_datafeed()
            except:
                agent, pod, symphony_sid = conn.connect()
            logging.error("failed to run main loop: %s" % err)