def set_device_event(self, device): time.ctime() # TODO: Do we need this line? if device.action == 'remove': fmt = '{0} - {1} reported a USB was {2.action}d from node {2.device_node}' else: fmt = '{0} - {1} reported a USB was {2.action}ed to node {2.device_node}' alert = fmt.format(time.strftime('%l:%M%p %Z on %b %d, %Y'), socket.gethostname(), device) print(alert) message_handler.send_message(alert)
def set_device_event(self, device): time.ctime() if device.action == 'remove': alert = '{0} - {1} reported a USB was {2.action}d from node {2.device_node}'.format( time.strftime('%l:%M%p %Z on %b %d, %Y'), socket.gethostname(), device) else: alert = '{0} - {1} reported a USB was {2.action}ed to node {2.device_node}'.format( time.strftime('%l:%M%p %Z on %b %d, %Y'), socket.gethostname(), device) print alert message_handler.send_message(alert)
def check_state(preserved_state): logging.debug('Getting current state of disk partitions.') current_state = psutil.disk_partitions() logging.debug( 'Comparing current state of disk partitions to the preserved state.') if len(current_state) < len(preserved_state): logging.debug( 'Found less disk partitions than in previous state. Checking difference.' ) devices = helpers.diff(preserved_state, current_state) logging.debug('Updating preserved state with current state.') preserved_state = current_state for device in devices: alert = '{} - {} reported {} was removed.'.format( time.strftime('%l:%M%p %Z on %b %d, %Y'), socket.gethostname(), device.mountpoint) send_message(alert) # logging.warning(alert) elif len(current_state) > len(preserved_state): logging.debug( 'Found more disk partitions than in previous state. Checking difference.' ) devices = helpers.diff(preserved_state, current_state) logging.debug('Updating preserved state with current state.') preserved_state = current_state for device in devices: alert = '{} - {} reported {} was added.'.format( time.strftime('%l:%M%p %Z on %b %d, %Y'), socket.gethostname(), device.mountpoint) send_message(alert) # logging.warning(alert) return preserved_state
def check_mode(alert): screensaver_monitor = os.popen('gnome-screensaver-command -q') line = screensaver_monitor.readline() if "is active" in line: message_handler.send_message(alert)