Пример #1
0
def main():
    """
    - The process of running the whole smsparser with the logic of parsing sms txt of users and loggers.

        **-db**
        -*Database host it can be (local or gsm2)*

        :Example Output: *gsm2*
        **-t**
        -*Smsinbox table (loggers or users)*

        :Example Output: *loggers* 
        **-m**
        -*Mode id* 
        **-g**
        -*GSM name (globe1, smart1, globe2, smart2)*
        **-s**
        -*GSM status of inbox/outbox*
        **-l**
        -*Number of message to read in the process*
        **-r**
        -*Default value False. Set True when running a test in the process*
        **-b**
        -*Default value False.*
        **-ns**
        -*Default value False.*

    .. note:: To run in terminal **python smsparser.py ** with arguments (** -db,-ns,-b,-r,-l,-s,-g,-m,-t**).
    """
    print('SMS Parser')
    args = get_arguments()

    if not args.bypasslock:
        lockscript.get_lock('smsparser %s' % args.table)

    allmsgs = smstables.get_inbox(host=args.dbhost,
                                  table=args.table,
                                  read_status=args.status,
                                  limit=args.messagelimit)

    if len(allmsgs) > 0:
        msglist = []
        for inbox_id, ts, sim_num, msg in allmsgs:
            sms_item = smsclass.SmsInbox(inbox_id, msg, sim_num, str(ts))
            msglist.append(sms_item)

        allmsgs = msglist

        try:
            parse_all_messages(args, allmsgs)
        except KeyboardInterrupt:
            print('>> User exit')
            sys.exit()

    else:
        print(dt.today().strftime("\nServer active as of %A, %B %d, %Y, %X"))
        return
Пример #2
0
def main():
    # get_network_info()
    # print common.mc
    lockscript.get_lock('xbeegate')
    args = get_arguments()

    xbee = get_xbee_handle()

    # get_rssi(xbee)
    if args.get_network_info:
        get_network_info()
    if args.get_rssi:
        for i in range(0, int(args.get_rssi)):
            print get_rssi(xbee)
    if args.sample_routers:
        routine(xbee)
Пример #3
0
def main():

    lockscript.get_lock('alertgenexec')

    print dt.today().strftime("%c")

    c = cfg.config()

    ongoing = []

    mc = memcache.Client(['127.0.0.1:11211'], debug=0)

    proc_limit = c.io.proc_limit

    while True:
        alertgenlist = mc.get('alertgenlist')

        print alertgenlist

        if alertgenlist is None:
            break

        if len(alertgenlist) == 0:
            break

        col = alertgenlist.pop()

        mc.set('alertgenlist', [])
        mc.set('alertgenlist', alertgenlist)

        command = "~/anaconda2/bin/python %s %s" % (c.fileio.alertgenscript,
                                                    col)

        print "Running", col, "alertgen"

        if lockscript.get_lock('alertgen for %s' % col, exitifexist=False):
            p = subprocess.Popen(command,
                                 stdout=subprocess.PIPE,
                                 shell=True,
                                 stderr=subprocess.STDOUT)
        else:
            continue

        while countAlertAnalysisInstances() > proc_limit:
            time.sleep(5)
            print '.',
def main():

    lockscript.get_lock('processmessages')

    # dbio.createTable("runtimelog","runtime")
    # logRuntimeStatus("procfromdb","startup")

    # force backup
    while True:
        allmsgs = dbio.getAllSmsFromDb("UNREAD")
        if len(allmsgs) > 0:
            msglist = []
            for item in allmsgs:
                smsItem = gsmio.sms(item[0], str(item[2]), str(item[3]),
                                    str(item[1]))
                msglist.append(smsItem)
            allmsgs = msglist

            read_success_list, read_fail_list = msgproc.ProcessAllMessages(
                allmsgs, "procfromdb")

            dbio.setReadStatus("READ-SUCCESS", read_success_list)
            dbio.setReadStatus("READ-FAIL", read_fail_list)
            sleeptime = 5
        else:
            # sleeptime = 60
            # print '>> Checking for alert sms'
            # alertmsg = CheckAlertMessages()
            # if alertmsg:
            #     WriteOutboxMessageToDb(alertmsg,smartnumbers)
            #     WriteOutboxMessageToDb(alertmsg,globenumbers)

            server.logRuntimeStatus("procfromdb", "alive")
            print dt.today().strftime(
                "\nServer active as of %A, %B %d, %Y, %X")
            return
Пример #5
0
def main(mc):
    print(dt.today().strftime("%c"))

    sc = mem.server_config()

    proc_limit = sc["io"]["proc_limit"]

    while True:
        alertgenlist = mc.get('alertgenlist')

        print(alertgenlist)

        if alertgenlist is None:
            break

        if len(alertgenlist) == 0:
            break

        alert_info = alertgenlist.pop()

        mc.set('alertgenlist', [])
        mc.set('alertgenlist', alertgenlist)

        python_path = sc['fileio']['python_path']
        alertgen = sc["fileio"]["alertgenscript"]
        command = '{} {} {} "{}"'.format(python_path, alertgen,
                                         alert_info['tsm_name'],
                                         alert_info['ts'])

        print("Running", alert_info['tsm_name'], "alertgen")

        if lockscript.get_lock('alertgen for %s' % alert_info['tsm_name'],
                               exitifexist=False):
            print('execute:', command)
            run_out = subprocess.run(command,
                                     stdout=subprocess.PIPE,
                                     shell=True,
                                     stderr=subprocess.STDOUT)
            print(run_out)
        else:
            continue

        while count_alert_analysis_instances() > proc_limit:
            time.sleep(5)
            print('.', )
Пример #6
0
def main(mc):
    print(dt.today().strftime("%c"))

    sc = mem.server_config()

    proc_limit = sc["io"]["proc_limit"]

    while True:
        alertgenlist = mc.get('alertgenlist')

        print(alertgenlist)

        if alertgenlist is None:
            break

        if len(alertgenlist) == 0:
            break

        alert_info = alertgenlist.pop()

        mc.set('alertgenlist', [])
        mc.set('alertgenlist', alertgenlist)

        command = "python %s %s '%s'" % (sc["fileio"]["alertgenscript"],
                                         alert_info['tsm_name'],
                                         alert_info['ts'])

        print("Running", alert_info['tsm_name'], "alertgen")

        if lockscript.get_lock('alertgen for %s' % alert_info['tsm_name'],
                               exitifexist=False):
            subprocess.Popen(command,
                             stdout=subprocess.PIPE,
                             shell=True,
                             stderr=subprocess.STDOUT)
        else:
            continue

        while count_alert_analysis_instances() > proc_limit:
            time.sleep(5)
            print('.', )
Пример #7
0
            #self.rssi_value = self.get_rssi_value()
            #status = self.get_modem_status()
            sys.stdout.flush()
            #sys.stdout.write("\r%d %d %d" % (self.rssi_value, status['rx_ongoing'], status['modem_clear']))
            sys.stdout.write("\r%s %d" % ('waiting for packets', ctr))


def signal_handler(signum, frame):
    raise SampleTimeoutException("Timed out!")


class SampleTimeoutException(Exception):
    pass


lockscript.get_lock('lora')
lora = LoRaRcvCont(verbose=False)
args = parser.parse_args(lora)

lora.set_mode(MODE.STDBY)
lora.set_pa_config(pa_select=1)
#lora.set_rx_crc(True)
#lora.set_coding_rate(CODING_RATE.CR4_6)
#lora.set_pa_config(max_power=0, output_power=0)
#lora.set_lna_gain(GAIN.G1)
#lora.set_implicit_header_mode(False)
#lora.set_low_data_rate_optim(True)
#lora.set_pa_ramp(PA_RAMP.RAMP_50_us)
#lora.set_agc_auto_on(True)

#print(lora)
Пример #8
0
def main():
    args = get_arguments()

    if args is None:
        print 'No arguments'
        return

    if args.print_memory:
        common.print_memory(args.print_memory)

    if args.initialize:
        common.main()
        xb.get_network_info()

    if args.initialize_gsm_module:
        lockscript.get_lock('gateway gsm')
        gsmio.init_gsm()
    if args.get_phonebook:
        dbio.get_phonebook_numbers()
    if args.write_custom_sms:
        custom_sms_routine()
    if args.send_outbox_messages:
        lockscript.get_lock('gateway gsm')
        send_unsent_msg_outbox()
    if args.debug_gsm:
        lockscript.get_lock('gateway gsm')
        gsmio.gsm_debug()
    if args.reset_gsm:
        lockscript.get_lock('gateway gsm')
        gsmio.reset_gsm()

    if args.reset_rain_value:
        rd.reset_rain_value()
    if args.rain_detect:
        rd.check_rain_value()

    if args.send_smsoutbox_memory:
        lockscript.get_lock('gateway gsm')
        send_smsoutbox_memory()
        send_unsent_msg_outbox()
    if args.purge_memory:
        lockscript.get_lock('gateway gsm')
        common.purge_memory(args.purge_memory)

    if args.set_system_time:
        set_system_time()
    if args.create_startup_message:
        create_startup_message()

    if args.sample_routers:
        lockscript.get_lock('xbeegate')
        xb.routine()