예제 #1
0
    def test_real_init_workflow(self, buildSensor, buildReporter):
        config = '''
        {
            "reporters":[
                "reporter1",
                "reporter2"
            ],
            "sensors":[
                "sensor1",
                "sensor2",
                "sensor3"
            ]
        }
        '''
        monitor = Monitor(json.loads(config))

        self.assertIs(len(monitor.getReporters()), 2)
        buildReporter.assert_has_calls(
            [mock.call('reporter1'),
             mock.call('reporter2')])

        self.assertIs(len(monitor.getSensors()), 3)
        buildSensor.assert_has_calls([
            mock.call('sensor1', monitor.sensorTrigger),
            mock.call('sensor2', monitor.sensorTrigger),
            mock.call('sensor3', monitor.sensorTrigger)
        ])
    def addAgent(self, idAgent, hostname, version, port, comunity):
        if idAgent in self.pool:
            return False

        tiempo_actual = int(time.time())

        newAgent = {
            'idAgent': idAgent,
            'hostname': hostname,
            'version': version,
            'port': port,
            'comunity': comunity,
            'time': tiempo_actual
        }

        t = Monitor(newAgent)
        self.pool.update({idAgent: t})
        t.start()

        self.data['agents'].append(newAgent)
        with open('agents.json', 'w') as f:
            json.dump(self.data, f)

        crearBases(idAgent)

        return True
예제 #3
0
 def __init__(self):
     Monitor.__init__(self, Constants.CPU_PERCENT_MONITOR)
     logger.info("Initializing CPU % Usage Monitor")
     self._minimum = 0.0
     self._maximum = 100
     logger.info("Minimum: {}, Current: {}, Maximum: {} ".format(
         self._minimum, self.poll(), self._maximum))
예제 #4
0
 def __init__(self):
     Monitor.__init__(self, Constants.BYTES_RECEIVED_MONITOR)
     logger.info("Initializing Bytes Received Monitor")
     self._casual_name = "Network Received Monitor"
     self._minimum = 0.0
     self._maximum = sys.maxsize
     logger.info("Minimum: {}, Current: {}, Maximum: {} ".format(self._minimum, self.poll(), self._maximum))
예제 #5
0
 def __init__(self):
     Monitor.__init__(self, Constants.SWAP_BYTE_MONITOR)
     logger.info("Initializing Swap MB Usage Monitor")
     memory_object = psutil.swap_memory()
     self._minimum = 0.0
     self._maximum = memory_object.total
     logging.info("Minimum: {}, Current: {}, Maximum: {} ".format(self._minimum, self.poll(), self._maximum))
예제 #6
0
    def sensorAppInit(self):

        # Initialize variables we need
        self.currentSensor = 1

        self.function_indicator = {
            1: self.ui.led_sensor,
            2: self.ui.led_temp,
            3: self.ui.led_hum,
            4: self.ui.led_t_alarm,
            5: self.ui.led_h_alarm
        }

        self.functionNumber = 1

        self.displayCelcius = False

        # Initialize the state of the UI
        self.ui.screen_output.setText("INITIALIZING")

        # Initialize UI timer for updates
        self.timer = QTimer()

        # Create instance of monitor class
        self.monitor = Monitor()

        # Register functions to corresponding event
        self.ui.pb_select.released.connect(self.select_button)
        self.ui.pb_up.released.connect(self.up_button)
        self.ui.pb_down.released.connect(self.down_button)
        self.ui.pb_convertTemp.released.connect(self.convertTemp_button)
        self.timer.timeout.connect(self.read_data)
        self.timer.start(10000)
예제 #7
0
 def __init__(self):
     Monitor.__init__(self, Constants.BYTES_RECEIVED_MONITOR)
     logger.info("Initializing Bytes Received Monitor")
     self._casual_name = "Network Received Monitor"
     self._minimum = 0.0
     self._maximum = sys.maxsize
     logger.info("Minimum: {}, Current: {}, Maximum: {} ".format(
         self._minimum, self.poll(), self._maximum))
 def __init__(self, log_file, last_id, monitorObj_id, monitorMetrics_id, monitorMetrics_name):
     Monitor.__init__(self, log_file, last_id, monitorObj_id, monitorMetrics_id, monitorMetrics_name)
     zhixinDelay_conf = parse_conf("./zhixinDelay.conf")
     self.hostname_list = []
     for item in zhixinDelay_conf:
         if(item['status'] == 1):
             self.hostname_list.append(item['hostname'])
             logging.info(self.hostname_list)
예제 #9
0
 def __init__(self, drive_root):
     Monitor.__init__(self, "{0} {1}".format(Constants.STORAGE_BYTE_MONITOR, str(drive_root)))
     logger.info("Initializing Storage Byte Monitor")
     self._drive_root = drive_root
     self._minimum = 0.0
     storage_object = psutil.disk_usage(self._drive_root)
     self._maximum = float(storage_object.total)
     logger.info("Minimum: {}, Current: {}, Maximum: {} ".format(self._minimum, self.poll(), self._maximum))
예제 #10
0
def main():
    config = Configuration()
    monitor = Monitor()

    monitor.Monitor()

    sleeptimer = float(config.sleeptimer)
    time.sleep(sleeptimer)
예제 #11
0
 def __init__(self):
     Monitor.__init__(self, Constants.RAM_BYTE_MONITOR)
     logger.info("Initializing RAM MB Usage Monitor")
     memory_object = psutil.virtual_memory()
     self._minimum = 0.0
     self._maximum = memory_object.total
     logger.info("Minimum: {}, Current: {}, Maximum: {} ".format(
         self._minimum, self.poll(), self._maximum))
예제 #12
0
def convertAlarmVals(F_flag):

	for sensor_num, entry in SensorTAlarms.items():
		if(not F_flag):
			SensorTAlarms[sensor_num]['val'] = math.floor(Monitor.fahrenheit_to_celsius(SensorTAlarms[sensor_num]['val']))
		else:
			SensorTAlarms[sensor_num]['val'] = math.floor(Monitor.celsius_to_fahrenheit(SensorTAlarms[sensor_num]['val']))

	return SensorTAlarms
 def __init__(self, log_file, last_id, monitorObj_id, monitorMetrics_id, monitorMetrics_name):
     Monitor.__init__(self, log_file, last_id, monitorObj_id, monitorMetrics_id, monitorMetrics_name)
     now_time = datetime.datetime.now()
     self.timeStamp=now_time.strftime('%Y-%m-%d-%H%M%S')
     self.dataList=list()
     self.dataDictTemp=dict()
     self.accountInfo =list()
     self.resList=list()
     self.finalresult=dict()
예제 #14
0
def handle_args(port, baudrate, timeout, page_dir, debug):
    """Load config and arguments, (arguments have precidence)"""

    # Remove the default logger and add one with a log level we set
    logger.remove(0)
    logger.start(sys.stderr, level=("DEBUG" if debug else "INFO"))
    logger.info("Starting NASMon...")
    
    mon = Monitor(port, baudrate, timeout, page_dir)
    mon.start()
예제 #15
0
def listen(ctx, verbose, home_id):
    """
    Passive monitoring of network
    :param ctx: shared context
    :param verbose: show received frames
    :param home_id: filter frames including specified home-id
    """
    # initialize
    signal.signal(signal.SIGINT, signal_handler)
    cfg = ctx.obj[CONFIGURATION]
    cfg.home_id = home_id
    cfg.verbose = verbose
    honeylog = ctx.obj[LOGGER]

    with multiprocessing.Manager() as manager:
        # initialize shared network and decoy information
        network = manager.dict(load_json(cfg.networks_path + '/' + cfg.network_file))
        decoys = manager.dict(load_json(cfg.networks_path + '/' + cfg.decoys_file))

        # init stats
        inner_stats = init_stats_dict()
        stats_real = manager.dict(inner_stats.copy())
        stats_malicious = manager.dict(inner_stats.copy())
        stats_invalid = manager.dict(inner_stats.copy())
        stats_in = manager.dict(inner_stats.copy())
        stats_out = manager.dict(inner_stats.copy())

        stats = {STAT_REAL: stats_real,
                 STAT_MALICIOUS: stats_malicious,
                 STAT_INVALID: stats_invalid,
                 STAT_IN: stats_in,
                 STAT_OUT: stats_out}

        frames_in = list()
        frames_out = list()

        # initialize components
        receiver = Receiver(cfg, network, decoys, honeylog, frames_in, frames_out)
        monitor = Monitor(cfg, network, decoys, honeylog, stats)

        receiver.monitor = monitor
        monitor.receiver = receiver

        # start configuration
        configuration_process = Process(target=set_configuration, args=(cfg, honeylog))
        configuration_process.start()

        # if not verbose
        if not verbose:
            # show only stats
            statsview_process = Process(target=stats_view, args=(stats, ctx.obj[DEBUG_LEVEL]))
            statsview_process.start()

        # start reception
        receiver.start(False, True)
예제 #16
0
    def __init__(self, channels, channel_names, conversion=None):

        Monitor.__init__(self, channels, channel_names)

        # Not sure what these two lines do ...
        self.task = None
        self.task_in_stream = None
        self.reader = None

        # Are we making a conversion from voltage to some other unit here?
        self.convert = isinstance(conversion, type({}))
        # print "NIDAQ self.convert  = {}".format(self.convert)
        # print "NIDAQ conversions = {}".format(conversion)
        # If so let's make sure the conversion dictionary is going to work
        err_type = "Error: Conversion should have lambda function at lowest level"
        if self.convert:
            err_shp = "Error: Conversion should have the same shape as channels"
            ch1 = self.channels.keys()
            ch2 = conversion.keys()
            assert set(ch1) == set(ch2), err_shp
            if self.many_channels:
                for key, value in self.channels.iteritems():
                    ch3 = value.keys()
                    assert isinstance(conversion[key], type({})), err_shp
                    ch4 = conversion[key].keys()
                    assert set(ch3) == set(ch4), err_shp
                for key, value in conversion.iteritems():
                    for func in value.values():
                        assert isinstance(func, type(lambda x: x + 1)), err_type
            else:
                for key, value in conversion.iteritems():
                    assert isinstance(value, type(lambda x: x + 1)), err_type

        self.conversion = conversion

        # List the analog in channels we will be monitoring on the DAQ
        if self.many_channels:  # For Issue
            self.channels_to_open = []
            print self.channels.values()
            for channel in self.channels.values():
                # make a list of all unique channels being opened
                self.channels_to_open = list(
                    set(self.channels_to_open) | set(channel.values()))
        else:
            self.channels_to_open = channels.values()

        self.channels_to_open.sort()
        print self.channels_to_open
        self.mychans = self.channel_string()

        # initialize data location
        self.data = numpy.zeros(len(self.channels_to_open))

        self.prepare_task()
    def __init__(self, *args, **kwargs):
        Monitor.__init__(self, *args, **kwargs)

        if HOSTNAME == "top-pi":
            self.sensor_group = 0
        elif HOSTNAME == "mid-pi":
            self.sensor_group = 1
        elif HOSTNAME == "bottom-pi":
            self.sensor_group = 2
        else:
            raise ValueError('unknown host')
예제 #18
0
def manage():
    # 新建任务
    global process_list
    logger.debug("任务个数 " + str(len(config["monitor"]["tasks"])))
    for task in config["monitor"]["tasks"]:
        p = Monitor(task)
        process_list.append(p)
        p.start()
        logger.debug("开始任务 " + repr(p) + " " + repr(task))

    return
예제 #19
0
 def __init__(self, drive_root):
     Monitor.__init__(
         self, "{0} {1}".format(Constants.STORAGE_BYTE_MONITOR,
                                str(drive_root)))
     logger.info("Initializing Storage Byte Monitor")
     self._drive_root = drive_root
     self._minimum = 0.0
     storage_object = psutil.disk_usage(self._drive_root)
     self._maximum = float(storage_object.total)
     logger.info("Minimum: {}, Current: {}, Maximum: {} ".format(
         self._minimum, self.poll(), self._maximum))
예제 #20
0
def record(ctx):
    """Records frames until users interrupt"""
    configuration = ctx.obj[CONFIGURATION]
    logger = ctx.obj[LOGGER]
    network = load_json(configuration.networks_path + '/' +
                        configuration.real_networks_name)
    decoys = load_json(configuration.networks_path + '/' +
                       configuration.virtual_networks_name)
    receiver = Receiver(configuration, network, decoys, logger, None, None)
    monitor = Monitor(configuration, network, decoys, logger, None, receiver)
    receiver.monitor = monitor
    monitor.record()
예제 #21
0
    def test_sensor_trigger(self, reporter_send):
        reporter = Reporter(json.loads('{ "id": "testReporter" }'))
        monitor = Monitor(self.EMPTY_CONFIG)
        monitor.reporters.append(reporter)

        events = monitor.sensorTrigger('testSensor')

        for event in events:
            event.wait()

        reporter_send.assert_called_once_with(
            'Sensor testSensor was triggered!', events[0])
예제 #22
0
    def __init__(self):
        Monitor.__init__(self)

        #make a brand new black (empty) matrix
        self.matrix = []
        for pixelOffY in range(self.config['STRIPES_NO'] *
                               self.config['STRIPES_BLOCKS']):
            self.matrix.append([])
            for pixelOffX in range(self.config['LED_COUNT_PER_STRIPE']):
                self.matrix[pixelOffY].append(
                    Pixel(pixelOffX * scale, pixelOffY * scale,
                          (000, 000, 000)))
    def __init__(self):
        self.data = {}
        self.data['agents'] = []
        self.pool = {}

        if os.path.exists('agents.json'):
            with open('agents.json', 'r') as f:
                self.data = json.load(f)
            for agent in self.data['agents']:
                t = Monitor(agent)
                self.pool.update({agent['idAgent']: t})
                t.start()
예제 #24
0
    def __init__(self):
        self.__database = Database()
        self.__monitor = Monitor()

        self.__minTemperature = self.__monitor.getMinTemperature()
        self.__maxTemperature = self.__monitor.getMaxTemperature()
        self.__minHumidity = self.__monitor.getMinHumidity()
        self.__maxHumidity = self.__monitor.getMaxHumidity()

        self.__arrayOfDates = self.__database.getDates()
        self.__avgTemperature = None
        self.__avgHumidity = None
        self.__status = "some status"
        self.__message = "some message"
예제 #25
0
def run():

    # the event for getting players actions
    player_action_received = threading.Event()
    player_action_received.set()

    # monitor is the GUI
    monitor = Monitor(player_action_received)

    # game is the manager
    game = Game(monitor, player_action_received)
    manager_thread = threading.Thread(target=game.start)
    manager_thread.start()

    # making the GUI appear
    monitor.start()
예제 #26
0
    def __init__(self):
        """ 
            On initialisation the MonitorAndNotify class reads the current data and inserts into the datbase every minute 
            and only sends a notification once a day
        
        """

        # Scheduler = Schedule()
        # Instantiate all relevant classes
        data = DataLogger()
        dataManager = DatabaseManager(data)
        monitor = Monitor()
        weather = Weather(data, dataManager, monitor)
        sense = VirtualSenseHat.getSenseHat()

        # Scheduler.createSchedule()

        # verify if the temperature is within the range
        weather.verifyTemperature()
        # verify if the humidity is within the range
        weather.verifyHumidity()

        # close the connection to the database
        dataManager.closeDBConnection()

        # clear anything displayed on the sense hat
        sense.clear()
예제 #27
0
def calChangedCB(gcal):
    '''Callback for calendar change from reciever'''
    print("Detected calendar changed.")
    mo_temp = []
    for component in gcal.walk():
        if component.name == "VEVENT":
            summary = component.get('summary')
            start_time = component.get('dtstart').dt
            end_time = component.get('dtend').dt
            time_delta = end_time - start_time

            # Create Cron Job base on schedule
            seconds = time_delta.total_seconds()
            comm0 = calendarParser.COMM + " " + summary + " " + str(seconds)

            # create new Monitor
            job = Monitor(0, comm0, start_time)
            mo_temp.append(job)

    print(utils.MONITORS)
    for mo in utils.MONITORS:
        mo.stop()

    utils.MONITORS = []
    timezone = pytz.timezone("US/Eastern")
    print mo_temp
    for mo in mo_temp:
        if mo.dt < timezone.localize(datetime.now()):
            continue
        utils.MONITORS.append(mo)
    for mo in utils.MONITORS:
        mo.start()
예제 #28
0
def scheduleEvent(gcal, comm):
    ''' Get all details of all scheduled VEVENTs'''

    # initialize scheduler for events
    s = sched.scheduler(time.time, time.sleep)
    timezone = pytz.timezone("US/Eastern")

    for component in gcal.walk():
        if component.name == "VEVENT":
            summary = component.get('summary')
            start_time = component.get('dtstart').dt
            end_time = component.get('dtend').dt
            time_delta = end_time - start_time

            # Create Cron Job base on schedule
            seconds = time_delta.total_seconds()
            #seconds = seconds % 60
            comm0 = COMM + " " + summary + " " + str(seconds)

            # create new Monitor
            if start_time < timezone.localize(datetime.now()):
                continue
            job = Monitor(s, comm0, start_time)
            utils.MONITORS.append(job)
            # createCronJob(comm0, start_time)
            # scheduleJob(comm0, start_time, s)

    # t = threading.Thread(target=s.run)
    # t.start()
    for mo in utils.MONITORS:
        mo.start()
예제 #29
0
def rebootServer():
    global monitor

    print("Loading data...")

    loadObjects()
    loadSettings()
    saveSettings()

    if (monitor != None):
        monitor.stop()
        del monitor

    monitor = Monitor(serverSettings['tempSensorGPIO'],
                      serverSettings['envUpdateMemory'],
                      serverSettings['envUpdatePeriod'])
    monitor.start()
예제 #30
0
def SetupMonitors():
    # Setup manager
    entityManager = EntityManager(config)

    # If I have not a list of monitors, I setup only a monitor
    if (consts.CONFIG_MONITORS_KEY not in config):
        monitor = Monitor(config, config, entityManager)
    else:  # More Monitors
        # Now setup monitors
        monitor_id = 0
        for monitor_config in config[consts.CONFIG_MONITORS_KEY]:
            monitor_id += 1
            monitor = Monitor(monitor_config, config, entityManager,
                              monitor_id)

    # Start sensors loop
    entityManager.Start()
예제 #31
0
    def setup(self):
        
        Monitor.setup(self)

        self.logger.debug("TCP:%i opening" % TCP_PORT)

        tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        while True:
            try:
                tcp.bind((TCP_HOST, TCP_PORT))
            except socket.error, msg:
                logger.debug(
                    "error connecting: %s - retry in 20s" % msg)
                time.sleep(20)
                continue
            break
예제 #32
0
def web():
    M = Monitor()
    try:
        html = """
        <style>
            table {
                border-collapse: collapse;
            }
            th, td {
                vertical-align: top;
                border: 1px solid black;
            }
            .mode-watch {
                background: #ffa;
            }
            .mode-blacklist {
                background: #fcc;
            }
        </style>
        <table>
        <tr>
            <th>wiki</th>
            <th>id</th>
            <th>name</th>
            <th>mode</th>
        </tr>
        """
        M.cur.execute(
            """SELECT `af_id`, `af_name`, `mode`, `wiki` FROM `abusefilter` ORDER BY `wiki` ASC, `af_id` ASC"""
        )
        rows = M.cur.fetchall()
        for row in rows:
            html += """
                <tr class="mode-{2}">
                    <td>{3}</td>
                    <td>{0}</td>
                    <td>{1}</td>
                    <td>{2}</td>
                </tr>
                """.format(row[0], row[1], row[2], row[3])
        html += '</table>'
        return html
    except Exception:
        M.error(traceback.format_exc())
        return "OK1"
예제 #33
0
    def __init__(self):
        """
            On initialisation the BluetoothManager class retrieves the temperature ranges from the Monitor Class
        """

        #declare variables that handle interactions with other classes
        self.__monitor = Monitor()
        self.__notifier = Notification()

        #declare variables that will store the head and message that will be sent via pushbullet
        self.__head = None
        self.__message = None

        #declare variables the store the ranges from the Monitor class using the classes methods
        self.__minTemperature = self.__monitor.getMinTemperature()
        self.__maxTemperature = self.__monitor.getMaxTemperature()
        self.__minHumidity = self.__monitor.getMinHumidity()
        self.__maxHumidity = self.__monitor.getMaxHumidity()
예제 #34
0
def web():
    M = Monitor()
    try:
        html = """
        <style>
            table {
                border-collapse: collapse;
            }
            th, td {
                vertical-align: top;
                border: 1px solid black;
            }
        </style>
        status
        <a href="./log?type=log">log</a>
        <a href="./blacklist">blacklist</a>
        <table>
        <tr>
            <th>database</th>
            <th>last time</th>
        </tr>
        """
        for table in tables:
            M.cur.execute("""SELECT MAX(`timestamp`) FROM """ + table)
            rows = M.cur.fetchall()
            if rows[0][0] is None:
                html += """
                    <tr>
                        <td>{}</td>
                        <td>No record</td>
                    </tr>
                    """.format(table)
            else:
                html += """
                    <tr>
                        <td><a href="{0}log?type={1}" target="_blank">{1}</td>
                        <td>{2}</td>
                    </tr>
                    """.format(M.siteurl, table, M.formattimediff(rows[0][0]))
        html += '</table>'
        return html
    except Exception:
        M.error(traceback.format_exc())
        return "OK1"
예제 #35
0
    def testBasicsWithAccessOnly(self):
        monitor = Monitor("testAccess")
        for i in range(5):
            starttime = datetime.now()
            waittime = self.waitForRandomMillis(55)
            monitor.mark(starttime)

        self.assertIsNone(monitor.processingCumulativeStats)
        self.assertIsNone(monitor.processingWindowStats)
        self.assertIsNotNone(monitor.accessCumulativeStats)
        self.assertIsNotNone(monitor.accessWindowStats)

        cumulativeAccessStats = monitor.getStats(True, False)
        self.assertEqual(4, cumulativeAccessStats.n)

        # exercise building summary info dictionary, value doesn't matter
        time.sleep(0.051)  # ensure window stats is different from cumulative
        summaryInfo = monitor.summaryInfo()
        import json; print json.dumps(summaryInfo, indent=4)
    def get(self, controller, redis_address):
        """
        Get a new reality capture scheduler

        :param controller: AgentController client instance.
        :param redis_address: Address of the redis instances that the jumpscripts will use to report stats and logs

        :return: Scheduler
        """
        return Monitor(controller, redis_address)
예제 #37
0
 def __init__(self):
     """Create the instrument object"""
     self.mon = Monitor()
     self.mon.login(b"Sesame")
     self.det = DetectorProcess()
     self.running = False#is the detector running?
     self.starttime = clock()#When the most recent run started
     self.config = XMLConfig()
     self.det.directory(self.config.getDir())
     self.subrun=0
	def addAgent(
		self, idAgent, hostname, version, port, comunity,
		ramReady, ramSet, ramGo,
		cpuReady, cpuSet, cpuGo,
		hddReady, hddSet, hddGo

	):
		if idAgent in self.pool:
			return False

		tiempo_actual = int(time.time())		

		newAgent = {  
		    'idAgent': idAgent,
		    'hostname': hostname,
		    'version': version,
		    'port': port,
		    'comunity': comunity,
		    'time': tiempo_actual,
		    'ramReady': ramReady,
		    'ramSet': ramSet,
		    'ramGo': ramGo,
		    'cpuReady': cpuReady,
		    'cpuSet': cpuSet,
		    'cpuGo': cpuGo,
		    'hddReady': hddReady,
		    'hddSet': hddSet,
		    'hddGo': hddGo
		}

		t = Monitor(newAgent)
		self.pool.update({idAgent: t})
		t.start()

		self.data['agents'].append(newAgent)
		with open('agents.json', 'w') as f:
		    json.dump(self.data, f)

		crearBases( idAgent )	
		crearBasesLb( comunity, hostname, port, idAgent )		

		return True
예제 #39
0
    def refresh_monitors(self):
        """
            The function is being called when a changes has been made an the monitors structure should get changed.
        """

        # If True that executor is the only one to get a window.
        if len(self.executors_monitors) == 1:
            pass
            # # Set the panel of the executor to the panel of the single monitor.
            # self.one_monitor_panel = self.executors_monitors.values()[0]

            # # Set the sizer of the monitors window to the single monitor panel.
            # self.SetSizer(self.one_monitor_panel_sizer)

        else:

            left_panel = Monitor(self.splitter, 0)
            right_panel = Monitor(self.splitter, 1)

            self.splitter.SplitVertically(left_panel, right_panel)
예제 #40
0
파일: gui.py 프로젝트: JoeBartelmo/PyDetect
    def init_ui(self):
        #make resizable
        self.grid_columnconfigure(0, weight=1)
        self.grid_rowconfigure(0, weight=1)

        self.notebook = Notebook(self)
        # define mainapp instance -- also manages above telemetry thread
        self.mainApplication = MainApplication(self, self.client_queue_cmd, self.client_queue_log, self.client_queue_telem, self.beam_gap_queue, self.destroyEvent, self.server_ip) 
        self.notebook.add(self.mainApplication, text = "Main")
        # define telemetry widgets
        self.monitor = Monitor(self, VisualConstants.MARS_PRIMARY(1))
        self.notebook.add(self.monitor, text = 'Monitor')
        self.notebook.grid(column = 0, row = 0, sticky = 'nsew')
        
        # menu -outside of notebook
        self.menu_ = TopMenu(self, '../gui/operations.json', self.client_queue_cmd, 'Commands')
        ### Add custom commands here
        self.menu_.add_menu_item('Reconnect to Cameras', self.mainApplication.start_streams, "View")
        self.menu_.add_menu_item('Left', self.mainApplication.focus_left, 'View/Camera Focus')
        self.menu_.add_menu_item('Center', self.mainApplication.focus_center, 'View/Camera Focus')
        self.menu_.add_menu_item('Right', self.mainApplication.focus_right, 'View/Camera Focus')
        self.menu_.add_menu_item('IBeam Display', self.beamGapGraph, 'View/Windows')
        self.menu_.add_menu_item('Toggle FOD Enabled', self.mainApplication.toggle_fod, 'View/Object Detection')
        self.menu_.add_menu_item('Set Ideal Images', self.mainApplication.define_ideal_images, 'View/Object Detection')
        ### 
        self.menu_.finalize_menu_items()
        self.config(menu=self.menu_)
        
        # start all operations here so we don't cause a hissyfit between tkinter and threads
        self.mainApplication.start_streams()
        #define telemetryThread
        self.tthread = TelemetryThread([self.mainApplication.telemetry_w, self.monitor], self.client_queue_telem, self.beam_gap_queue)
        self.tthread.start()

        # title and icon
        self.wm_title('Hyperloop Imaging Team')
        #this is garbage, i hate tkinter
        #self.img = ImageTk.PhotoImage(file='rit_imaging_team.xbm')
        #self.tk.call('wm', 'iconphoto', self._w, self.img)
        #self.iconbitmap('@rit_imaging_team.xbm')
        #call destroyCallback on clicking X
        self.protocol('WM_DELETE_WINDOW', self.destroyCallback)
        

        #assign dimensions and locatin on screen
        width = 900
        height = 500
 
        x = (self.winfo_screenwidth() // 2) - (width // 2)
        y = (self.winfo_screenheight() // 2) - (height // 2)
        self.geometry('{}x{}+{}+{}'.format(width, height, x, y))
        
        self.update()
예제 #41
0
 def __init__(self, host, port, type, id = 0):
     super(Ssh, self).__init__()
     
     self.auth = None  # created by PyUML
     self.server = Server(host, port, type, id)
     
     self.client = paramiko.SSHClient()
     self.client.load_system_host_keys()
     self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
     self.isConnected = False
     
     self.monitoring = Monitor(self)
예제 #42
0
    def setup(self):

        Monitor.setup(self)
        self.logger.debug("wattson: port=%s" % self.port)
        
        # 19200, 8N1
        # 8 data bits, no parity bit, 1 stop bit
        self.connection = serial.Serial(
            port=self.port,
            baudrate=19200,
            parity=serial.PARITY_NONE,
            stopbits=serial.STOPBITS_ONE,
            bytesize=serial.EIGHTBITS,
            timeout=1)
        self.connection.close()
        self.connection.open()
        assert self.connection.isOpen()

        data = self.communicate("nows")

        self.logger.info("connected to wattson device %s" % data)
예제 #43
0
    def testBasicsWithProcessing(self):
        monitor = Monitor("testBasics", defaultWindowWidth=100, defaultSegmentWidth=50)
        for i in range(5):
            starttime = datetime.now()
            waittime = self.waitForRandomMillis(55)
            endtime = datetime.now()
            monitor.mark(starttime, endtime)

        # Default stats are processingCumulativeStats
        self.assertEqual(monitor.processingCumulativeStats, monitor.getStats())

        # Make sure getStats behaves as advertised
        self.assertEqual(monitor.processingCumulativeStats, monitor.getStats(access=False, window=False))
        self.assertNotEqual(monitor.processingCumulativeStats, monitor.getStats(access=False, window=True))
        self.assertEqual(monitor.accessCumulativeStats, monitor.getStats(access=True, window=False))
        self.assertNotEqual(monitor.accessCumulativeStats, monitor.getStats(access=True, window=True))

        cumulativeProcessingStats = monitor.getStats()
        self.assertEqual(5, cumulativeProcessingStats.n)

        # exercise building summary info dictionary, value doesn't matter
        time.sleep(0.051)  # ensure window stats is different from cumulative
        summaryInfo = monitor.summaryInfo()
        import json; print json.dumps(summaryInfo, indent=4)
예제 #44
0
 def test_update_infinit(self):
     #remove this for normal testing
     monitor = Monitor(PL)
     while True:
         time.sleep(.2)
         monitor.update()
예제 #45
0
__author__ = 'huaxz'
from Monitor import  Monitor
import StockList
import time
M=Monitor()
shList=['sh'+item for item in StockList.shStockList]
szList=['sz'+item for item in StockList.szStockList]
stocklist= shList+szList
#开始遍历
while True:
    temp=M.monitor(stocklist)
    time.sleep(3)

예제 #46
0
 def __init__(self, log_file, last_id, monitorObj_id, monitorMetrics_id, monitorMetrics_name):
     Monitor.__init__(self, log_file, last_id, monitorObj_id, monitorMetrics_id, monitorMetrics_name)
     now_time = datetime.datetime.now()
     self.dataList=list()
     self.accountInfo =list()
예제 #47
0
파일: gui.py 프로젝트: JoeBartelmo/PyDetect
class GUI(tk.Tk):
    """
    Start graphical interface for client.

    Args:
        client_queue_cmd: queue to send commands
        client_queue_log: queue to get logging info
        client_queue_telem: queue to get telemetry data
        beam_gap_queue: queue to retrieve beam gap data (any queue will do, this is handled via the gui, through the telemetry queue)
        @depricated
        server_ip: server IP address for rtp stream access
    """
    def __init__(self, client_queue_cmd, client_queue_log, client_queue_telem, beam_gap_queue, destroyEvent, server_ip, **kwargs):
        tk.Tk.__init__(self, **kwargs)
        self.client_queue_cmd = client_queue_cmd
        self.client_queue_log = client_queue_log
        self.client_queue_telem = client_queue_telem
        self.beam_gap_queue = beam_gap_queue
        self.server_ip = server_ip
        self.destroyEvent = destroyEvent

    def init_ui(self):
        #make resizable
        self.grid_columnconfigure(0, weight=1)
        self.grid_rowconfigure(0, weight=1)

        self.notebook = Notebook(self)
        # define mainapp instance -- also manages above telemetry thread
        self.mainApplication = MainApplication(self, self.client_queue_cmd, self.client_queue_log, self.client_queue_telem, self.beam_gap_queue, self.destroyEvent, self.server_ip) 
        self.notebook.add(self.mainApplication, text = "Main")
        # define telemetry widgets
        self.monitor = Monitor(self, VisualConstants.MARS_PRIMARY(1))
        self.notebook.add(self.monitor, text = 'Monitor')
        self.notebook.grid(column = 0, row = 0, sticky = 'nsew')
        
        # menu -outside of notebook
        self.menu_ = TopMenu(self, '../gui/operations.json', self.client_queue_cmd, 'Commands')
        ### Add custom commands here
        self.menu_.add_menu_item('Reconnect to Cameras', self.mainApplication.start_streams, "View")
        self.menu_.add_menu_item('Left', self.mainApplication.focus_left, 'View/Camera Focus')
        self.menu_.add_menu_item('Center', self.mainApplication.focus_center, 'View/Camera Focus')
        self.menu_.add_menu_item('Right', self.mainApplication.focus_right, 'View/Camera Focus')
        self.menu_.add_menu_item('IBeam Display', self.beamGapGraph, 'View/Windows')
        self.menu_.add_menu_item('Toggle FOD Enabled', self.mainApplication.toggle_fod, 'View/Object Detection')
        self.menu_.add_menu_item('Set Ideal Images', self.mainApplication.define_ideal_images, 'View/Object Detection')
        ### 
        self.menu_.finalize_menu_items()
        self.config(menu=self.menu_)
        
        # start all operations here so we don't cause a hissyfit between tkinter and threads
        self.mainApplication.start_streams()
        #define telemetryThread
        self.tthread = TelemetryThread([self.mainApplication.telemetry_w, self.monitor], self.client_queue_telem, self.beam_gap_queue)
        self.tthread.start()

        # title and icon
        self.wm_title('Hyperloop Imaging Team')
        #this is garbage, i hate tkinter
        #self.img = ImageTk.PhotoImage(file='rit_imaging_team.xbm')
        #self.tk.call('wm', 'iconphoto', self._w, self.img)
        #self.iconbitmap('@rit_imaging_team.xbm')
        #call destroyCallback on clicking X
        self.protocol('WM_DELETE_WINDOW', self.destroyCallback)
        

        #assign dimensions and locatin on screen
        width = 900
        height = 500
 
        x = (self.winfo_screenwidth() // 2) - (width // 2)
        y = (self.winfo_screenheight() // 2) - (height // 2)
        self.geometry('{}x{}+{}+{}'.format(width, height, x, y))
        
        self.update()

    def killMars(self):
        '''
        Sends the kill command to Mars
        '''
        logger.debug('GUI Killing Mars...')
        self.client_queue_cmd.put('exit')

    def displayMarsDisconnected(self):
        tkMessageBox.showerror('Lost connection to Mars', 'The client has lossed connection to mars, closing application.')
        self.destroyClient()

    def destroyClient(self):
        logger.debug('GUI Killing Main App...')
        self.menu_.destroy() 
        self.mainApplication.close_()
        logger.debug('GUI Killing Monitor app...')
        self.monitor.destroy()
        self.notebook.destroy()
        logger.debug('GUI Killing Self...')
        self.killTelemThread()
        logger.debug('GUI Dead')
        self.quit()
        self.destroy()
 
    def killTelemThread(self):
        """ Customized quit function to allow for safe closure of processes. """
        logger.debug('GUI Killing Telemetry...')
        self.tthread.stop()
        if self.tthread.is_alive():
            self.tthread.join()

    def destroyCallback(self):
        '''
        Function called when the window handle Destory is clicked (the x)
        Opens up a small prompt asking if you wanna kill mars
        '''
        logger.debug('GUI entering destroy callback...')
        result = tkMessageBox.askyesno('Leaving GUI, Should Mars be Disabled?', 'Leaving GUI, should Mars be Disabled?')

        if result:
            self.killMars()
        self.destroyClient()

    def beamGapGraph(self):
        '''
        Function that launches the Beam Gap Widget that displays the current beam distances
        in readalbe form.
        '''
        if getattr(self, 'top', False) == False:
            self.top = BeamGapWidget(self, self.beam_gap_queue)
            self.top.title("VALMAR Beam Gap")
        else:
            if self.top['state'] != 'normal':
                self.top = BeamGapWidget(self, self.beam_gap_queue)
                self.top.title("VALMAR Beam Gap")

    def start(self):
        '''
        Starts the root window
        '''
        
        self.init_ui()
        try:
            self.mainloop()
        except KeyboardInterrupt:
            self.destroyClient()
예제 #48
0
 def __init__(self):
     Monitor.__init__(self, Constants.CPU_PERCENT_MONITOR)
     logger.info("Initializing CPU % Usage Monitor")
     self._minimum = 0.0
     self._maximum = 100
     logger.info("Minimum: {}, Current: {}, Maximum: {} ".format(self._minimum, self.poll(), self._maximum))
예제 #49
0
 def __init__(self, *args, **kwargs):
     Monitor.__init__(self, *args, **kwargs)
예제 #50
0
import daemon
import lockfile

from config import config

from Monitor import Monitor

context = daemon.DaemonContext(
    working_directory="/data/log/",
    umask=0o002,
    pidfile=lockfile.FileLock(config["pidfile"]),
    # pidfile=open(config["pidfile"], "w"),
    stdout=open(config["debug_log"], "w"),
    stderr=open(config["error_log"], "w"),
)

monitor = Monitor()

with context:
    monitor.run()
예제 #51
0
class Ssh(QtCore.QObject):
    """
    Class created by PyUML

    
    # PyUML: Do not remove this line! # XMI_ID:_sfuNQBCnEd-9mr2Tj73dvA

    # PyUML: Associations of this class:
    # PyUML: Association (being 'src') to class ServersPool (being 'dst') in package /base/ 
    # PyUML: Association (being 'dst') to class Server (being 'src') in package /base/ 
    # PyUML: Association (being 'dst') to class Auth (being 'src') in package /base/ 
    # PyUML: Association (being 'src') to class Monitor (being 'dst') in package /base/ 
"""
    server = None  # created by PyUML

    def __init__(self, host, port, type, id = 0):
        super(Ssh, self).__init__()
        
        self.auth = None  # created by PyUML
        self.server = Server(host, port, type, id)
        
        self.client = paramiko.SSHClient()
        self.client.load_system_host_keys()
        self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        self.isConnected = False
        
        self.monitoring = Monitor(self)
    
    def __del__(self):
        self.close()
        
    def set_auth(self, login, password = '******'):
        self.auth = Auth(login, password)
    
    def connect_thread(self):
        try:
            if self.auth.is_rsa():
                self.client.connect(self.server.host, self.server.port, self.auth.login, key_filename=self.auth.get_rsa_files(), timeout=25)
            else:
                self.client.connect(self.server.host, self.server.port, self.auth.login, self.auth.password, timeout=25)
            self.isConnected = self.client.get_transport().is_active()
            
            if(self.isConnected):
                self.client.get_transport().set_keepalive(300)
            
            hostname, os = self.sendCommand('hostname && uname').split()
            self.server.set_hostname(hostname)
            self.server.set_os(os.lower())
            
            # Emits signal that server is connected
            self.emit(QtCore.SIGNAL('connected'), self)
            
            return True
        
        except:
            # Emits signal that server is connected
            self.emit_notconnected()
            #self.emit(QtCore.SIGNAL('notConnected'), self)
            
            print 'Unable to connect to %s:%s with login %s, pass %s' % (self.server.host, self.server.port, self.auth.login, self.auth.password)
            QtCore.QCoreApplication.processEvents();
            
            try:
                self.client.close()
            except:
                pass
            return False

    def connect(self):
        try:
            self.close()
        finally:
            # Connect to the servers (thread-safe)
            # Random avoid to fail a connection on windows when all connections
            # are initialized
            global connectDelay
            t = Timer(connectDelay, self.connect_thread)
            t.start()
            connectDelay += .1

    def close(self):
        self.client.close()
        if self.isConnected:
            # Emits signal that server is connected
            self.emit_notconnected()
        self.isConnected = False
        #self.emit(QtCore.SIGNAL('notConnected'), self)

    def sendCommand(self, command):
        if self.isConnected:
            if not self.client.get_transport().is_active():
                self.isConnected = False
                # Emits signal that server is connected
                self.emit_notconnected()
                #self.emit(QtCore.SIGNAL('notConnected'), self)
            
            stdin, stdout, stderr = self.client.exec_command(command)
            response = stdout.read()
            
            if response == False:
                return stderr.read()
            else:
                return response
        else:
            return False
    
    def sendInteractiveCommand(self, command, args):
        if self.isConnected:
            i = 0
            stdin, stdout, stderr = self.client.exec_command(command)
            while stdout.channel.closed is False:
                stdin.write('%s\n' % args[i])
                stdin.flush()
                ++i
            # Reinitialize sudo
            self.sendCommand('sudo -k')
            response = stdout.read()
            
            if response == False:
                return stderr.read()
            else:
                return response
        else:
            return False
    
    def monitor(self, interval = 5.0):
        self.monitoring.set_interval(interval)
        self.monitoring.start()
    
    def open_interactive_shell(self):
        if platform.system() == 'Linux':
            try:
                # Gnome
                subprocess.Popen('gnome-terminal -e "ssh ' + self.server.host + ' -p ' + str(self.server.port) + ' -l ' + str(self.auth.login) + '"', shell=True)
                
            except:
                # KDE
                try:
                    subprocess.Popen('konsole -e "ssh ' + self.server.host + ' -p ' + str(self.server.port) + ' -l ' + str(self.auth.login) + '"', shell=True)
                except:
                    print 'No terminal found'
            
        elif platform.system() == 'Darwin':
            subprocess.Popen('/bin/sh base/term.sh /usr/bin/ssh ' + self.server.host + ' -p ' + str(self.server.port) + ' -l ' + str(self.auth.login), shell=True)
            #try:
            #    # Mac OSX
            #    subprocess.Popen('open -n -a /Applications/Utilities/Terminal.app /usr/bin/ssh ' + self.server.host + ' -p ' + str(self.server.port) + ' -l ' + str(self.auth.login), shell=True)
            #except:
            #    print 'No terminal found'
            
        elif platform.system() == 'Windows':
            # Windows
            try:
                subprocess.Popen('putty.exe -ssh -2 -P ' + str(self.server.port) + ' ' + str(self.auth.login) + '@' + self.server.host + ' -pw ' + str(self.auth.password), shell=True)
            except:
                print 'No terminal found'
    
    def emit_notconnected(self):
        self.emit(QtCore.SIGNAL('notConnected'), self)
예제 #52
0

<<<<<<< HEAD

schemas = SchemaStore(getFiles())
schemas.printSchemas()

"""fix parsing, get flows to work. work on architecture. make canonical topology, with ip addresses.
     switch to layer 3 routing. check latency properly, testing different maounts
      and cleearing the ARP cache. then combine flows with latency """
    
openflow = Openflow(schemas)
openflow.start()
sflow = Sflow(schemas)
sflow.start()
monitor = Monitor(sflow,openflow)
monitor.start()
"""another infinite loop means it needs its own thread so it doesn't stop routing"""
    

    #sflow = Sflow(schemas)
    #sflow.start()

     # if sflow.recentMatches:
       # print sflow.recentMatches
=======
def monitor():

    schemas = SchemaStore(getFiles())
    schemas.printSchemas()
예제 #53
0
class Instrument:
    """This class handles the collection of normalized neutron data

    The class contains both a monitor object and a detector process
    to provide normalized monitor data

    """
    def __init__(self):
        """Create the instrument object"""
        self.mon = Monitor()
        self.mon.login(b"Sesame")
        self.det = DetectorProcess()
        self.running = False#is the detector running?
        self.starttime = clock()#When the most recent run started
        self.config = XMLConfig()
        self.det.directory(self.config.getDir())
        self.subrun=0

    def getPassword(self):
        return self.config.getPassword()

    def updateRunnumber(self):
        """Update to the next data run"""
        self.subrun=0
        runnumber = self.config.nextRun()

    def start(self):
        """Begin neutron collection"""
        self.subrun += 1
        runnumber = self.config.getRunnumber()
        logging.info("Starting run %d.%04d" % (runnumber,self.subrun))
        self.det.runnumber(self.subrun)        
        self.det.directory(self.config.getDir())
        self.starttime = clock()        
        self.mon.startrun(runnumber,self.subrun)
        self.det.start()

    def getMonitorFile(self):
        """Return the absolute path for the monitor file"""
        path = self.config.getDir()
        path += "%04dmon.txt"%(self.subrun)
        return path

    def getLocalMonitorFile(self):
        """Return the relative path for the monitor file"""
        return "%04dmon.txt"%(self.subrun)

    def getRunnumber(self):
        """Return the current run number"""
        return self.config.getRunnumber()

    def getPath(self):
        """Return the current directory for saved data"""
        return self.config.getDir()

    def stop(self):
        """End collection of neutrons"""
        self.mon.stoprun()
        self.det.stop()
        stop = clock()
        detector_count = self.det.count()
        monitor_count = self.mon.getCount()
        logging.info("Run %d.%04d ended" % (self.config.getRunnumber(),self.subrun))
        logging.info("Time:\t\t%f seconds"%(stop-self.starttime))
        logging.info("Detector:\t%d counts"%detector_count)
        logging.info("Monitor:\t%d counts"%monitor_count)
        logging.debug("Saving Monitor File")
        with open(self.getMonitorFile(),"w") as stream:
                self.mon.localSave(stream,(clock()-self.starttime)*1000)
        logging.debug("Run Stopped")
        return (stop-self.starttime,monitor_count,detector_count)

    def setParam(self,option,value):
        """Change the status of the detector"""
        self.det.setParam(option,value)

    def query(self,option):
        """Find the status of an instrument parameter"""
        return self.det.query(option)
        

    def timedrun(self,time):
        """Collect data for a set number of seconds"""
        self.start()
        sleep(time)
        self.stop()

    def __del__(self):
        """Destructor that handles the monitor login"""
        self.mon.logout()
        del self.mon
        del self.det
 def __init__(self, log_file, last_id, monitorObj_id, monitorMetrics_id, monitorMetrics_name):
     Monitor.__init__(self, log_file, last_id, monitorObj_id, monitorMetrics_id, monitorMetrics_name)
     self.dataList = list()
     self.warnList = list()
 def __init__(self, log_file, last_id, monitorObj_id, monitorMetrics_id, monitorMetrics_name):
     Monitor.__init__(self, log_file, last_id, monitorObj_id, monitorMetrics_id, monitorMetrics_name)
     self.TSMInterface_conf = parse_conf("./TSMInterface.conf")
예제 #56
0
handler = logging.handlers.RotatingFileHandler(WXLOG_FILE, maxBytes = 1024*1024, backupCount = 5) # 实例化handler
fmt = '%(asctime)s <%(filename)s><%(lineno)d>: [%(levelname)s] - %(message)s'
handler2 = logging.handlers.RotatingFileHandler(MOLOG_FILE, maxBytes = 1024*1024, backupCount = 5) # 实例化handler

formatter = logging.Formatter(fmt)   #
handler.setFormatter(formatter)      #
handler2.setFormatter(formatter)
logger = logging.getLogger('wx')    #
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
logger1 = logging.getLogger('monitor')    #
logger1.addHandler(handler2)
logger1.setLevel(logging.DEBUG)



with aiohttp.ClientSession() as client, aiohttp.ClientSession() as rclient:
    wx = Wechat(client)
    robot = RobotEngine(rclient, config.apikey)
    msg = MsgHandler(wx, robot)
    god = Monitor(wx)
    tasks = [
            wx.sync() ,
            wx.sendmsg() ,
            wx.updategroupinfo() ,
            msg.msgloop() ,
            god.monitor()
            ]
    asyncio.get_event_loop().run_until_complete(asyncio.wait(tasks))
예제 #57
0
 def test_update(self):
     monitor = Monitor(PL)
     monitor.update()
 def __init__(self, log_file, last_id, monitorObj_id, monitorMetrics_id, monitorMetrics_name):
     Monitor.__init__(self, log_file, last_id, monitorObj_id, monitorMetrics_id, monitorMetrics_name)
     self.account = list()
     self.dataList = list()
     self.dataListTemp = list()
     self.resList = list()
예제 #59
0
def DeferredStageoutHPCJob(job_dir, deferred_stageout_logfile=False, **kwargs):
    """
    Performs stageing out preparation for the HPC job in specified directory.

    :param job_dir:     (string)    directory with a job.
                        mandatory parameter

    :param deferred_stageout_logfile: (string|False)    template name for deferred log stageout
                                                        Replaces "{job_id}" with current job id like
                                                        "log-{job_id}.txt" -> "log-124124.txt"
                                        Default False

    Other parameters are passed into other functions

    :return: (bool) the fact of stageout being performed
    """
    log('Deferred stageout from HPC job directory "%s"' % job_dir)

    file_path = job_dir + "/" + hpc_jobState_file_wildcart
    current_dir = os.getcwd()
    log("Working on %s" % file_path)
    log("Chdir from current dir %s to %s" % (current_dir, job_dir))
    pUtil.chdir(job_dir)

    try:
        with LockFileWrapper(file_path) as is_locked:
            if not is_locked:
                return False

            from json import load

            with open(file_path) as data_file:
                HPC_state = load(data_file)
            job_state_file = HPC_state["JobStateFile"]
            job_command = HPC_state["JobCommand"]
            # global_work_dir = HPC_state['GlobalWorkingDir']
            JS = JobState()
            JS.get(job_state_file)
            _job, _site, _node, _recoveryAttempt = JS.decode()

            with LogWrapper(deferred_stageout_logfile, _job.jobId) as logger:
                jobStatus, jobAttemptNr, jobStatusCode = pUtil.getJobStatus(
                    _job.jobId, DorE(kwargs, "pshttpurl"), DorE(kwargs, "psport"), DorE(kwargs, "pilot_initdir")
                )
                # recover this job?
                if jobStatusCode == 20:
                    log("Received general error code from dispatcher call (leave job for later pilot)")
                    # release the atomic lockfile and go to the next directory
                    # releaseAtomicLockFile(fd, lockfile_name)
                    return False
                elif jobStatus in finalJobStates or "tobekilled" in _job.action:
                    log(
                        "Job %s is currently in state '%s' with attemptNr = %d (according to server - will not"
                        " perform staging out)" % (_job.jobId, jobStatus, jobAttemptNr)
                    )
                    # releaseAtomicLockFile(fd, lockfile_name)
                    return False

                # update job state file at this point to prevent a parallel pilot from doing a simultaneous recovery
                _retjs = pUtil.updateJobState(_job, _site, _node, _recoveryAttempt)
                # releaseAtomicLockFile(fd, lockfile_name)

        monitor = Monitor(env)
        monitor.monitor_recovery_job(_job, _site, _node, job_command, job_state_file, recover_dir=job_dir)

        log("Chdir back to %s" % current_dir)
        pUtil.chdir(current_dir)

        panda_jobs = glob(job_dir + "/PandaJob_*_*")
        panda_logs = glob(job_dir + "/*.log.tgz.*")
        if panda_jobs or panda_logs:
            log(
                "Number of founded panda jobs: %d, number of panda log tar file %d, will not remove job dir"
                % (len(panda_jobs), len(panda_logs))
            )
        else:
            log(
                "Number of founded panda jobs: %d, number of panda log tar file %d, will remove job dir"
                % (len(panda_jobs), len(panda_logs))
            )
            log("Remove job dir %s" % job_dir)
            os.system("rm -rf %s" % job_dir)
        return True
    except:
        log("Failed to start deferred stage out for HPC job: %s" % traceback.format_exc())
        return False
예제 #60
0
 def __init__(self, *args, **kwargs):
     Monitor.__init__(self, *args, **kwargs)
     self.port = '/dev/ttyUSB0'
     # stty settings
     self.stty = "5:0:8be:0:0:0:0:0:0:a" + ":0" * 26