Пример #1
0
def main():
    g = gpio.gpio()
    w = watchdog.watchdog(gpio=g)

    while True:
        w.pet()
        common.msleep(10 * 1000)
Пример #2
0
 def reminder(self):
     eveInfo = watchdog.watchdog()
     responseSet = eveInfo.subscriberStatus
     for row in responseSet:
         sinceLastCheck = getLastTimeChecked(row['last_checked'])
         if row['hoursLeft'] < 24 and sinceLastCheck < 8:
             acc.send_pager('sip:{0}'.format(row['owner']), 'Dear {0} your character {1} has last {2} hours left in skill queue'.format(row['owner'], row['characterName'], row['hoursLeft']))
             eveInfo.setCheckedTime(row['characterID'])
Пример #3
0
 def getStatus(self, subscriber):
     subscriber = truncateSubscriberName(subscriber)
     eveInfo = watchdog.watchdog(subscriber)
     responseSet = eveInfo.subscriberStatus
     if not responseSet:
         response='You are not registered.\nPlease register by sending message in format: REGISTER {keyID} {vCode}'
         self.acc.send_pager('sip:{0}'.format(subscriber), response)
         return
     response = 'Dear {0}, '.format(subscriber)
     for row in responseSet:
         if 'Error' in row.keys():
             self.acc.send_pager('sip:{0}'.format(subscriber), 'Error fetching information from API')
             return
         response += 'Your cahracter {0} has {1} hours left in skill queue. Skillqueue ends at {2}\n'.format(row['characterName'], row['hoursLeft'], row['endTime'])
     self.acc.send_pager('sip:{0}'.format(subscriber), response)
Пример #4
0
 def __init__(self, port):
   #telnet communication to lecroy
   self.com = lecroy_com(port)
   #number of boards and channels per board
   self.nbd = 1
   self.nchan = 8
   #offset in board numbering
   self.bdofs = 12
   #list of board objects
   self.bdlist = []
   for ibd in range(self.nbd):
     self.bdlist.append(board(ibd, self.nchan, self.bdofs, self.com))
   #configuration file
   self.confnam = "config.csv"
   self.cframe = pandas.read_csv(self.confnam)
   #watchdog timer with 10 sec timeout
   self.wdt = watchdog(10, self.bdlist)
   self.wdt.start()
   #mainframe PVs
   self.hvstat_pv = builder.boolIn("hvstat", ZNAM="OFF", ONAM="ON")
   self.hvon_pv = builder.boolOut("hvon", ZNAM=0, ONAM=1, HIGH=0.1, initial_value=0, on_update=self.do_on)
   self.hvoff_pv = builder.boolOut("hvoff", ZNAM=0, ONAM=1, HIGH=0.1, initial_value=0, on_update=self.do_off)
   self.link_pv = builder.boolOut("link", ZNAM=0, ONAM=1, HIGH=0.7, initial_value=0)
Пример #5
0
 def __init__(self, pvname, desc, mail):
     self.mail = mail
     self.desc = desc
     self.pvname = pvname
     self.initialized = False
     self.sevr_val = 0
     self.alarm_flag = False
     self.msg_counter = 0
     self.max_msg = 4
     self.max_msg_reached = False
     self.is_masked = False
     self.stat_pv = PV(self.pvname + ".STAT")
     self.val_pv = PV(self.pvname + ".VAL")
     self.sevr_pv = PV(self.pvname + ".SEVR",
                       callback=self.on_sevr_change,
                       connection_callback=self.on_connection_change)
     if self.sevr_pv.status is None:
         self.initialized = True
         self.on_connection_change(False)
     self.wdt = watchdog(3600, self.reset_max_msg)
     self.tid = threading.Thread(target=self.monit_loop)
     self.tid.daemon = True
     self.tid.start()
Пример #6
0
npp = 12
ntile = 31
elist = []
#east/west loop
for ew in range(0, 2):
    elist.append([])
    #PP loop
    for ipp in range(0, npp + 1):
        elist[ew].append([])
        #tile loop
        for itile in range(ntile + 1):
            #PP starts at 1, handled in epdchan constructor
            elist[ew][ipp].append(epdchan(ew, ipp, itile))

#watchdog timer for 60 seconds
wdt = watchdog(60, elist)

#file holding alarm limit values
csvlim = "limits.csv"
lframe = pd.read_csv(csvlim)
#set initial alarm values
elist[0][0][0].limits.imon_max = lframe['imon_max'][0]
elist[0][0][0].limits.rmon_min = lframe['rmon_min'][0]
elist[0][0][0].limits.rmon_max = lframe['rmon_max'][0]
elist[0][0][0].limits.temp_max = lframe['temp_max'][0]


#functions to show alarm limits
#_____________________________________________________________________________
def get_imon_max():
    return elist[0][0][0].limits.imon_max
Пример #7
0
npp = 12
ntile = 31
elist = []
#east/west loop
for ew in range(0,2):
  elist.append([])
  #PP loop
  for ipp in range(0,npp+1):
    elist[ew].append([])
    #tile loop
    for itile in range(ntile+1):
      #PP starts at 1, handled in epdchan constructor
      elist[ew][ipp].append( epdchan(ew, ipp, itile) )

#watchdog timer for 60 seconds
wdt = watchdog(60, elist)

#file holding alarm limit values
csvlim = "limits.csv"
lframe = pd.read_csv(csvlim)
#set initial alarm values
elist[0][0][0].limits.imon_max = lframe['imon_max'][0]
elist[0][0][0].limits.rmon_min = lframe['rmon_min'][0]
elist[0][0][0].limits.rmon_max = lframe['rmon_max'][0]
elist[0][0][0].limits.temp_max = lframe['temp_max'][0]

#functions to show alarm limits
#_____________________________________________________________________________
def get_imon_max():
  return elist[0][0][0].limits.imon_max
Пример #8
0
    cashier = Cashier(session, accountant, bitcoinrpc, compropago,
                      cold_wallet_period=cold_wallet_period,
                      sendmail=sendmail,
                      minimum_confirmations=minimum_confirmations,
                      alerts=alerts_proxy,
                      bitgo=bitgo,
                      bitgo_private_key_file=bitgo_private_key_file,
                      testnet=config.getboolean("cashier", "testnet"),
    )

    administrator_export = AdministratorExport(cashier)
    accountant_export = AccountantExport(cashier)
    webserver_export = WebserverExport(cashier)

    watchdog(config.get("watchdog", "cashier"))
    router_share_async(administrator_export,
                     config.get("cashier", "administrator_export"))
    pull_share_async(accountant_export,
                    config.get("cashier", "accountant_export"))
    router_share_async(webserver_export,
                       config.get("cashier", "webserver_export"))

    public_server = Resource()
    public_server.putChild('compropago', CompropagoHook(cashier))
    private_server = Resource()
    private_server.putChild('bitcoin', BitcoinNotify(cashier))


    if config.getboolean("webserver", "ssl"):
        key = config.get("webserver", "ssl_key")
Пример #9
0
# a remote sysadmin to fix the system between reboots
TTL = 120

usage = f'''{sys.argv[0]} [username] [password]

This program monitors connection state via ICMP messages. If it can ping the default gateway but not an external 
address, it will reboot your modem.
'''


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='This program monitors connection state via ICMP messages. If it can '
                                                 'ping the default gateway but not an external address, it will reboot '
                                                 'your modem.')
    parser.add_argument('username', metavar='username', type=str, nargs=1, help='user to log in as')
    parser.add_argument('password', metavar='password', type=str, nargs=1, help='password to use when logging in')
    parser.add_argument('--modem-url', dest='modem_url', type=str, default='http://192.168.100.1',
                        help='modem address')
    parser.add_argument('--check-address', dest='check_address', type=str, help='internal address to ping as a check')
    args = parser.parse_args()

    logging.basicConfig(level=logging.INFO)
    try:
        modem = modems.NetgearCM1100(args.username, args.password, url=args.modem_url)
    except IndexError:
        print(usage)
        print('ERROR: must provide username and password as arguments')
        exit(1)
    else:
        watchdog.watchdog(modem, internal_addr=args.check_address)
Пример #10
0
class AccountantExport(ComponentExport):
    def __init__(self, ledger):
        self.ledger = ledger
        ComponentExport.__init__(self, ledger)

    @export
    @schema("rpc/ledger.json#post")
    def post(self, *postings):
        return self.ledger.post(list(postings))

def create_posting(type, username, contract, quantity, direction, note=None, timestamp=None):
    if timestamp is None:
        timestamp = util.dt_to_timestamp(datetime.datetime.utcnow())

    return {"username":username, "contract":contract, "quantity":quantity,
            "direction":direction, "note": note, "type": type, "timestamp": timestamp}

if __name__ == "__main__":
    fo = log.startLogging(sys.stdout)
    fo.formatTime = lambda x: datetime.datetime.fromtimestamp(x).strftime("%Y-%m-%d %H:%M:%S.%f")
    engine = database.make_engine()
    timeout = config.getint("ledger", "timeout")
    ledger = Ledger(engine, timeout)
    accountant_export = AccountantExport(ledger)
    watchdog(config.get("watchdog", "ledger"))
    router_share_async(accountant_export,
            config.get("ledger", "accountant_export"))
    reactor.run()

Пример #11
0
    administrator_export = AdministratorExport(engine)
    accountant_port = config.getint("engine", "accountant_base_port") + contract.id

    administrator_port = config.getint("engine", "administrator_base_port") + contract.id
    router_share_async(administrator_export, "tcp://127.0.0.1:%d" % administrator_port)

    logger = LoggingListener(engine, contract)
    accountant = accountant.AccountantProxy("push",
                                            config.get("accountant", "engine_export"),
                                            config.getint("accountant", "engine_export_base_port"))
    accountant_notifier = AccountantNotifier(engine, accountant, contract)
    webserver = push_proxy_async(config.get("webserver", "engine_export"))
    webserver_notifier = WebserverNotifier(engine, webserver, contract)


    watchdog(config.get("watchdog", "engine") %
             (config.getint("watchdog", "engine_base_port") + contract.id))

    forwarder = connect_publisher(config.get("safe_price_forwarder", "zmq_frontend_address"))

    safe_price_notifier = SafePriceNotifier(session, engine, accountant, webserver, forwarder, contract)
    accountant_export = AccountantExport(engine, safe_price_notifier, webserver_notifier)
    router_share_async(accountant_export, "tcp://127.0.0.1:%d" % accountant_port)

    engine.add_listener(logger)
    engine.add_listener(accountant_notifier)
    engine.add_listener(webserver_notifier)
    engine.add_listener(safe_price_notifier)

    # Cancel all orders with some quantity_left that have been dispatched but not cancelled
    try:
        for order in session.query(models.Order).filter_by(
Пример #12
0
 def openwatchdog(self):
     if self.gpio is not None:
         self.watchdog = watchdog.watchdog(gpio=self.gpio)
     else:
         self.logger.log.error("Cannot open watchdog interface before GPIO")
Пример #13
0
        bitcoinrpc,
        compropago,
        cold_wallet_period=cold_wallet_period,
        sendmail=sendmail,
        minimum_confirmations=minimum_confirmations,
        alerts=alerts_proxy,
        bitgo=bitgo,
        bitgo_private_key_file=bitgo_private_key_file,
        testnet=config.getboolean("cashier", "testnet"),
    )

    administrator_export = AdministratorExport(cashier)
    accountant_export = AccountantExport(cashier)
    webserver_export = WebserverExport(cashier)

    watchdog(config.get("watchdog", "cashier"))
    router_share_async(administrator_export,
                       config.get("cashier", "administrator_export"))
    pull_share_async(accountant_export,
                     config.get("cashier", "accountant_export"))
    router_share_async(webserver_export,
                       config.get("cashier", "webserver_export"))

    public_server = Resource()
    public_server.putChild('compropago', CompropagoHook(cashier))
    private_server = Resource()
    private_server.putChild('bitcoin', BitcoinNotify(cashier))

    if config.getboolean("webserver", "ssl"):
        key = config.get("webserver", "ssl_key")
        cert = config.get("webserver", "ssl_cert")
Пример #14
0
                   quantity,
                   direction,
                   note=None,
                   timestamp=None):
    if timestamp is None:
        timestamp = util.dt_to_timestamp(datetime.datetime.utcnow())

    return {
        "username": username,
        "contract": contract,
        "quantity": quantity,
        "direction": direction,
        "note": note,
        "type": type,
        "timestamp": timestamp
    }


if __name__ == "__main__":
    fo = log.startLogging(sys.stdout)
    fo.formatTime = lambda x: datetime.datetime.fromtimestamp(x).strftime(
        "%Y-%m-%d %H:%M:%S.%f")
    engine = database.make_engine()
    timeout = config.getint("ledger", "timeout")
    ledger = Ledger(engine, timeout)
    accountant_export = AccountantExport(ledger)
    watchdog(config.get("watchdog", "ledger"))
    router_share_async(accountant_export,
                       config.get("ledger", "accountant_export"))
    reactor.run()
Пример #15
0
	def test_watchdog_context_raises(self):
		try:
			with watchdog(3):
				time.sleep(4)
		except Timeout, e:
			pass;
Пример #16
0
	def test_watchdog_context_does_not_raise(self):
		try:
			with watchdog(3):
				time.sleep(2);
		except Timeout, e:
			self.fail("sleep(2) shoud not raise under a 3 second watchdog");
Пример #17
0
	def __init__(self, CFG):
		self.CFG = CFG

		if CFG.has_section('net') and CFG.has_option('net', 'host'):
			self.host = CFG.get('net', 'host')
		else:
			self.host = '' #socket.getsockname()

		if CFG.has_section('net') and CFG.has_option('net', 'port'):
			self.port = int(CFG.get('net', 'port'))
		else:
			self.port = 8568

		#the maximum number of waiting socket connections
		if CFG.has_section('net') and CFG.has_option('net', 'backlog'):
			self.backlog = int(CFG.get('net', 'backlog'))
		else:
			self.backlog = 100

		if CFG.has_section('net') and CFG.has_option('net', 'socketBufferSize'):
			self.socketBufferSize = int(CFG.get('net', 'socketBufferSize'))
		else:
			self.socketBufferSize = 4096

		if CFG.has_section('all') and CFG.has_option('all', 'workspace'):
			self.home = CFG.get('all', 'workspace')
		else:
			print 'Value not provided for workspace.  Aborting...';
			sys.exit(1);

		self.logfile = open(self.home + 'logs/server.log', 'ab')

		if CFG.has_section('server') and CFG.has_option('server', 'numSingleProcesses'):
			self.numSingleProcesses = int(CFG.get('server', 'numSingleProcesses'))
		else:
			self.numSingleProcesses = 1

		if CFG.has_section('server') and CFG.has_option('server', 'maxJobAge'):
			self.maxJobAge = int(CFG.get('server', 'maxJobAge'))
		else:
			self.maxJobAge = 7

		if CFG.has_section('net') and CFG.has_option('net', 'serverSocketRetry'):
			self.serverSocketRetry = int(CFG.get('net', 'serverSocketRetry'))
		else:
			self.serverSocketRetry = 15
			
		if CFG.has_section('net') and CFG.has_option('net', 'serverSelectTimeout'):
			self.serverSelectTimeout = int(CFG.get('net', 'serverSelectTimeout'))
		else:
			self.serverSelectTimeout = 30
			
		self.logMutex = threading.Lock()
		self.log("Starting server")

		self.server = None
		self.jobQueue = Queue()

		#this keeps track of which thread has which job
		self.singleProcesses = {}

		self.running = True
		self.input = []
		self.watchdog = watchdog(self)
		self.waitMutex = threading.Lock()

		self.log("Starting " + str(self.numSingleProcesses) + " singleProcess instances.")

		#Create numsingleProcesses singleProcess's, indexed by an id.
		for i in range(self.numSingleProcesses):
			i = str(i)
			self.log("Starting thread 'singleProcess" + i + "'.")
			self.watchdog.addThread(i)
			self.singleProcesses[i] = singleProcess( i, self)
			self.singleProcesses[i].start()

		self.log("Starting thread 'watchdog'.")
		self.watchdog.start()