Ejemplo n.º 1
0
    def addpl(self, message):
        msg = message.lower()

        syslog.syslog("run %s" % self.manage)
        if 'britney' in msg:
            self.speak("euh, ça non je ne peux pas, Britney ça fait saigner les oreilles, désolé")
            return 0

        if ' dion' in msg:
            self.speak("mais tu sais qu'écouter Céline Dion tue un chaton ?")
            return 0

        if ' biolay' in msg:
            self.speak("pitié pas Biolay")
            return 0

        if ';' in msg:
            self.speak("hum j'aime pas trop les points-virgules")
            return 0

        if '&' in msg:
            self.speak("je n'aime pas les esperluettes d'abord")
            return 0

        for plp in self.pl_prefix:
            if msg.startswith("%s: %s" % (self.nick, plp)):
                index = len(self.nick) + 2 + len(plp) + 1
                lookup = message[index:]
                syslog.syslog("action: lookup %s " % lookup)
                res = subprocess.check_output([self.manage, 'lookup_add_playlist', lookup])
                self.speak(res.rstrip())
Ejemplo n.º 2
0
 def load_files(self):
     """
     read user-written Py3status class files for dynamic inclusion
     """
     for include_path in self.include_paths:
         include_path = os.path.abspath(include_path) + '/'
         if os.path.isdir(include_path):
             for f_name in os.listdir(include_path):
                 try:
                     module, class_inst = self.load_from_file(
                         include_path + f_name
                     )
                     if module and class_inst:
                         self.classes[f_name] = (class_inst, [])
                         self.cache[f_name] = {}
                         for method in dir(class_inst):
                             # exclude private and other decorated methods
                             # such as @property or @staticmethod
                             if method.startswith('_'):
                                 continue
                             else:
                                 m_type = type(getattr(class_inst, method))
                                 if 'method' in str(m_type):
                                     self.classes[f_name][1].append(method)
                 except Exception:
                     err = sys.exc_info()[1]
                     syslog(LOG_ERR, "loading %s failed (%s)"
                                     % (f_name, str(err)))
Ejemplo n.º 3
0
 def parse_interface_control(self):
     subtype = self.get_byte(2)
     if subtype == SUBTYPE_INTERFACE_RESPONSE:
         self.parse_interface_response()
     else:
         syslog.syslog(syslog.LOG_DEBUG,
                       "Unknown interface control packet 0x%x" % subtype)
Ejemplo n.º 4
0
 def warn_broken_packages(self, pkgs, err):
     pkgs = ', '.join(pkgs)
     syslog.syslog('broken packages after installation: %s' % pkgs)
     self.db.subst('ubiquity/install/broken_install', 'ERROR', err)
     self.db.subst('ubiquity/install/broken_install', 'PACKAGES', pkgs)
     self.db.input('critical', 'ubiquity/install/broken_install')
     self.db.go()
Ejemplo n.º 5
0
 def _reset(self):
     syslog.syslog(syslog.LOG_DEBUG,
                   "Resetting device.")
     self._issue_interface_command(COMMAND_RESET)
     syslog.syslog(syslog.LOG_DEBUG,
                   "Waiting for device to boot up.")
     time.sleep(2)
Ejemplo n.º 6
0
 def _print_line(self, data, use_syslog, splunk, idstring, cmd="compute"):
     if use_syslog is True:
         if os.uname()[0] == "Darwin":
             syslog.openlog("Python")
         if splunk is True:
             message = ("memory=%s,workload=%s,vcpus=%s,instances=%s,"
                        "vcpu_used=%s,memory_used=%s,hypervisor=%s,"
                        "cmd=%s" % (
                        data['memory_mb'], data['current_workload'],
                        data['vcpus'], data['running_vms'],
                        data['vcpus_used'], data['memory_mb_used'],
                        data['hypervisor_hostname'], cmd))
         else:
             message = ("%s,%s,%s,%s,%s,%s,%s,%s" % (
                        data['memory_mb'], data['current_workload'],
                        data['vcpus'], data['running_vms'],
                        data['vcpus_used'], data['memory_mb_used'],
                        data['hypervisor_hostname'], cmd))
         if idstring is not None:
             message = ("%s,%s" % (idstring, message))
         syslog.syslog(syslog.LOG_ALERT, message)
     else:
         self.app.stdout.write(str(datetime.now()) + ",")
         if idstring is not None:
             self.app.stdout.write(idstring + ",")
         self.app.stdout.write(str(data['memory_mb']) + ",")
         self.app.stdout.write(str(data['current_workload']) + ",")
         self.app.stdout.write(str(data['vcpus']) + ",")
         self.app.stdout.write(str(data['running_vms']) + ",")
         self.app.stdout.write(str(data['vcpus_used']) + ",")
         self.app.stdout.write(str(data['memory_mb_used']) + ",")
         self.app.stdout.write(str(data['hypervisor_hostname']) + ",")
         self.app.stdout.write(str("%s\n" % cmd))
Ejemplo n.º 7
0
def sendrequest(request):
    try:
        context = zmq.Context.instance()

        client = context.socket(zmq.REQ)
        client.connect("ipc:///var/run/clearwater/alarms")

        poller = zmq.Poller()
        poller.register(client, zmq.POLLIN)

        for reqelem in request[0:-1]:
            client.send(reqelem, zmq.SNDMORE)

        client.send(request[-1])

        socks = dict(poller.poll(2000))

        if client in socks:
            message = client.recv()
        else:
            syslog.syslog(syslog.LOG_ERR, "dropped request: '%s'" % " ".join(request))

        context.destroy(100)

    except Exception as e:
        syslog.syslog(syslog.LOG_ERR, str(e))
Ejemplo n.º 8
0
def zabbix_report():
    global g_report_total
    global g_report_exception
    global g_report_error
    global g_report_thread

    if g_report_total == 0:
        g_report_thread = threading.Timer(g_report_thread_time, zabbix_report)
        g_report_thread.start()
        return

    host_ = '221.228.202.134'
    port_ = 3320
    user_ = 'testing'
    password_ = 'testingvpl'
    report_db_ = 'vpl_report'

    conn = MySQLdb.connect(host=host_, port=port_, user=user_, passwd=password_, db=report_db_)
    cur = conn.cursor()
    syslog.syslog(syslog.LOG_INFO, "insert vpl quality for %s, ts: %d, total: %d, exception: %d, error: %d"
                  % (g_type, int(time.time()), g_report_total, g_report_exception, g_report_error))

    cur.execute('INSERT INTO `vpl_report`(`ts`, `total`, `exception`, `error`, `type`) VALUES (%d, %d, %d, %d, "%s")'
                % (int(time.time()), g_report_total, g_report_exception, g_report_error, g_type))
    conn.commit()
    cur.close()
    conn.close()

    g_report_total = 0
    g_report_exception = 0
    g_report_error = 0
    g_report_thread = threading.Timer(g_report_thread_time, zabbix_report)
    g_report_thread.start()
Ejemplo n.º 9
0
def get_rtt():
    global g_cnt_total
    global g_cnt_get_exception
    global g_cnt_get_error
    global g_report_total
    global g_report_exception
    global g_report_error

    g_cnt_total += 1
    g_report_total += 1

    file_size = 0
    total_size = 0
    try:
        start_time = time.time()
        request = urllib2.Request(url=g_http_res)
        response = urllib2.urlopen(request, timeout=g_overtime)

        if 'content-length' in response.headers:
            file_size = int(response.headers['content-length'])

        while True:
            chunk = response.read(1024)
            if not chunk:
                break
            total_size += len(chunk)
        total_time = time.time() - start_time
    except Exception, e:
        g_cnt_get_exception += 1
        g_report_exception += 1
        syslog.syslog(syslog.LOG_WARNING, 'Warn: http get exception %s' % e)
Ejemplo n.º 10
0
 def look_human(self):
     syslog.syslog('Looking human for %s' % self.nickname)
     # build a streamer of a sample of tweets
     self.build_streamer()
     ## schedule each bot to tweet a random tweet pulled from corpus at random specified time depending on if its a weekday or not
     # get todays date
     today = date.today() 
     # get whether its a weekday or weekend
     week_type = self.get_weektime(today.weekday())
     # get minimum datetime and maximum datetime to spawn intervals in between them
     mintime = time(self.scheduled_tweets[week_type]['times'][0], 0)
     mindt = datetime.combine(today, mintime)
     maxtime = time(self.scheduled_tweets[week_type]['times'][1], 0)
     maxdt = datetime.combine(today, maxtime)
     # get each bot, and use gevent to spawn_later tasks based on the week_type with a random tweet
     for bot in self.bot_list:
        intervals = [ self.randtime(mindt, maxdt) for x in xrange(self.scheduled_tweets[week_type]['num_tweets']) ]
        s = ' '.join([ str(datetime.fromtimestamp(interval)) for interval in intervals ])
        syslog.syslog('%s times to tweet -> %s' % (bot.name, s))
        bot.last_intervals = intervals
        # assign the gevent to spawn_later by mapping each interval generated, find the time delta to determine number of seconds until event
        # and then pull a random tweet from the corpus
        map(lambda time: gevent.spawn_later(time - int(datetime.now().strftime('%s')), bot.tweet, self.get_random_tweet()), intervals)
     # reset corpus
     self.twitter_corpus = []
Ejemplo n.º 11
0
def timer_save_result():
    global g_save_thread
    global g_rtt_list
    global g_cnt_total
    global g_cnt_get_exception
    global g_cnt_get_error

    g_mutex.acquire()
    if not g_rtt_list:
        syslog.syslog(syslog.LOG_WARNING, 'rtt list is empty')
        if g_cnt_total > 0:
            g_cnt_get_error = g_cnt_total - g_cnt_get_exception
            g_rtt_list.append(65535)
        else:
            g_mutex.release()
            g_save_thread = threading.Timer(g_save_thread_time, timer_save_result)
            g_save_thread.start()
            return

    output_list = [str(item) for item in g_rtt_list]
    syslog.syslog(syslog.LOG_INFO, 'rtt statistic list: %s' % g_list_sep.join(output_list))
    report_data()
    # clear statistic list
    g_rtt_list = list()
    g_cnt_total = 0
    g_cnt_get_exception = 0
    g_cnt_get_error = 0

    g_mutex.release()
    g_save_thread = threading.Timer(g_save_thread_time, timer_save_result)
    g_save_thread.start()
Ejemplo n.º 12
0
def main():
    """ Background process loop, runs as backend daemon for all zones. only one should be active at all times.
        The main job of this procedure is to sync the administration with the actual situation in the ipfw firewall.
    """
    bgprocess = CPBackgroundProcess()
    bgprocess.initialize_fixed()

    while True:
        try:
            # open database
            bgprocess.db.open()

            # reload cached arp table contents
            bgprocess.arp.reload()

            # update accounting info, for all zones
            bgprocess.db.update_accounting_info(bgprocess.ipfw.list_accounting_info())

            # process sessions per zone
            for zoneid in bgprocess.list_zone_ids():
                bgprocess.sync_zone(zoneid)

            # close the database handle while waiting for the next poll
            bgprocess.db.close()

            # sleep
            time.sleep(5)
        except KeyboardInterrupt:
            break
        except SystemExit:
            break
        except:
            syslog.syslog(syslog.LOG_ERR, traceback.format_exc())
            print(traceback.format_exc())
            break
Ejemplo n.º 13
0
 def initSignalHandlers(self):
     sigs = [ signal.SIGINT, signal.SIGTERM, signal.SIGUSR1, signal.SIGUSR2 ]
     for s in sigs:
         syslog.syslog( syslog.LOG_DEBUG, "DEBUG  Registering handler for "+
                        self.sigmap[s])
         sig = Signal.create(s,self)
         sig.signal.connect(self.handleSignal)
Ejemplo n.º 14
0
    def debconffilter_done(self, dbfilter):
        """Called when an asynchronous debconffiltered command exits.

        Returns True if the exiting command is self.dbfilter; frontend
        implementations may wish to do something special (such as exiting
        their main loop) in this case."""

        if dbfilter is None:
            name = 'None'
            self.dbfilter_status = None
        else:
            name = dbfilter.__module__
            if dbfilter.status:
                self.dbfilter_status = (name, dbfilter.status)
            else:
                self.dbfilter_status = None
        if self.dbfilter is None:
            currentname = 'None'
        else:
            currentname = self.dbfilter.__module__
        syslog.syslog(syslog.LOG_DEBUG,
                      "debconffilter_done: %s (current: %s)" %
                      (name, currentname))
        if dbfilter == self.dbfilter:
            self.dbfilter = None
            return True
        else:
            return False
Ejemplo n.º 15
0
def find_grub_target():
    # This needs to be somewhat duplicated from grub-installer here because we
    # need to be able to show the user what device GRUB will be installed to
    # well before grub-installer is run.
    try:
        boot = ""
        root = ""
        regain_privileges()
        p = PartedServer()
        for disk in p.disks():
            p.select_disk(disk)
            for part in p.partitions():
                part = part[1]
                if p.has_part_entry(part, "mountpoint"):
                    mp = p.readline_part_entry(part, "mountpoint")
                    if mp == "/boot":
                        boot = disk.replace("=", "/")
                    elif mp == "/":
                        root = disk.replace("=", "/")
        drop_privileges()
        if boot:
            return boot
        elif root:
            return root
        return "(hd0)"
    except Exception, e:
        drop_privileges()
        import syslog

        syslog.syslog("Exception in find_grub_target: " + str(e))
        return "(hd0)"
Ejemplo n.º 16
0
    def check(self, write = False):
        self._ldapquery.appendAttributeList(self._uidlist)
        self._ldapquery.appendAttributeList(self._singleattributes)
        self._ldapquery.appendAttributeList(self._phoneattributes)
        self._ldapquery.appendAttributeList(self._listattributes.keys())

        syslog.syslog("Starting the Automatic Phonebook Update")
        print "Starting the Automatic Phonebook Update"
        try:
            self._openldap()
            self._getlists()
            self._getusers()
            self._checkuids()
            self._checkphones()
            self._checksingleattributes()
            self._checklistattributes()
            
            # OPW Specific Checks
            self._checkphotoandworkforceID()
            self._checkfullname()        
                
            self._writechanges(write)
        finally:
            self._closeldap()
        syslog.syslog("Finished the Automatic Phonebook Update")
        print "Finished the Automatic Phonebook Update"
Ejemplo n.º 17
0
 def log(self, msg, level='info'):
     """
     log this information to syslog or user provided logfile.
     """
     if not self.config['log_file']:
         # If level was given as a str then convert to actual level
         level = LOG_LEVELS.get(level, level)
         syslog(level, u'{}'.format(msg))
     else:
         # Binary mode so fs encoding setting is not an issue
         with open(self.config['log_file'], 'ab') as f:
             log_time = time.strftime("%Y-%m-%d %H:%M:%S")
             # nice formating of data structures using pretty print
             if isinstance(msg, (dict, list, set, tuple)):
                 msg = pformat(msg)
                 # if multiline then start the data output on a fresh line
                 # to aid readability.
                 if '\n' in msg:
                     msg = u'\n' + msg
             out = u'{} {} {}\n'.format(log_time, level.upper(), msg)
             try:
                 # Encode unicode strings to bytes
                 f.write(out.encode('utf-8'))
             except (AttributeError, UnicodeDecodeError):
                 # Write any byte strings straight to log
                 f.write(out)
Ejemplo n.º 18
0
 def process_IN_CREATE(self,event):
     if (event.mask & pyinotify.IN_ISDIR):
         pass
     else:
         syslog.syslog("creat " + event.pathname)
         ScanWebshell(event.pathname)
         ScanEvilFuctions(event.pathname)
Ejemplo n.º 19
0
 def process_IN_MODIFY(self,event):
     if (event.mask & pyinotify.IN_ISDIR):
         pass
     else:
         syslog.syslog("modify " + event.pathname)
         ScanWebshell(event.pathname)
         ScanEvilFuctions(event.pathname)
Ejemplo n.º 20
0
  def Run(self):
    line1 = self.readline()
    if not line1 == "HELO\t2":
      self.reply('FAIL')
      self.readline()
      sys.exit(1)
    else:
      self.reply('OK\t%s' % BANNER)

    if not self.local_ip:
      self.SlowGetOwnIp()

    while self.KeepRunning():
      line = self.readline()
      if line == '':
        break
      try:
        query = line.split("\t")
        if DEBUG: syslog.syslog(syslog.LOG_DEBUG, 'Q: %s' % query)
        if len(query) == 7:
          self.Lookup(query)
          self.query_count += 1
        elif len(query) == 2 and query[0] == 'AXFR':
          # Just fail silently on this one
          self.reply("FAIL")
        else:
          self.FlushLogBuffer()
          self.reply("LOG\tPowerDNS sent bad request: %s" % query)
          self.reply("FAIL")
      except Exception, err:
        self.redis_pdns.Disconnect()
        self.FlushLogBuffer()
        self.reply("LOG\tInternal Error: %s" % err)
        self.reply("FAIL")
Ejemplo n.º 21
0
 def _log_syslog(self, prio):
     if self.__ident:
         syslog.openlog(ident=self.__ident, facility=self.__fac)
         syslog.syslog(prio, self.__last_message)
         syslog.closelog()
     else:
         syslog.syslog(prio | self.__fac, self.__last_message)
Ejemplo n.º 22
0
	def sendUpstream(self, data):

		key = self.key
		server = self.server

		try:
			params = urllib.urlencode(data)
			headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}

			try:
				conn = httplib.HTTPConnection(server)
				conn.request("POST", "/data?key=" + self.key)
				resp = conn.getresponse()

			except:
				syslog.syslog(syslog.LOG_WARNING, "Unable to connect to server, attempting to save monitoring data")

				try:
					self.save(data)

				except:
					syslog.syslog(syslog.LOG_WARNING, "Error: unable to save monitoring data")
					raise

				raise httplib.HTTPException

		except:
			raise httplib.HTTPException()
Ejemplo n.º 23
0
 def mkdir(self, path=None):
     try:
         os.makedirs(path)
         syslog.syslog(syslog.LOG_NOTICE, 'created local directory: %s' % path)
     except OSError as e:
         if e.errno != errno.EEXIST or not os.path.exists(path):
             raise
Ejemplo n.º 24
0
    def stop(self):
        """Stop the daemon."""

        # Get the pid from the pidfile
        try:
            with open(self.pidfile, "r") as pidf:
                pid = int(pidf.read().strip())
        except IOError:
            pid = None

        if not pid:
            message = "pidfile {0} does not exist. " + "Daemon not running?\n"
            sys.stderr.write(message.format(self.pidfile))
            return  # not an error in a restart

        # Try killing the daemon process
        try:
            while True:
                os.kill(pid, signal.SIGTERM)
                time.sleep(0.1)
        except OSError as err:
            e = str(err.args)
            if e.find("No such process") > 0:
                if os.path.exists(self.pidfile):
                    os.remove(self.pidfile)
            else:
                print(str(err.args))
                sys.exit(1)
        syslog.syslog(syslog.LOG_INFO, "{}: stopped".format(os.path.basename(sys.argv[0])))
Ejemplo n.º 25
0
def lo():
    """ The program turns on LED
    """

    # Set up logging
    syslog.syslog('Lo Starting')
    logging.basicConfig(filename='ha-conn.log',level=logging.DEBUG)
    logging.info('Lo starting')

    # set up the MQTT environment
    client = mqtt.Client()
    client.on_connect = on_connect
    client.on_message = on_message

    client.connect("127.0.0.1", 1883, 60)

    topic = "homeassistant/2/101/1/P"
    msgDict = {}
    msgDict['action'] = "P"
    msgDict['result'] = 0
    msgDict['req_ID'] = 4
    msgDict['deviceID'] = 101
    msgDict['instance'] = 1
    msgDict['float1'] = 300 

    msg = json.dumps(msgDict) 
    print(topic + " " + msg)

    logging.info(topic + " " + msg)
    publish.single(topic, msg, hostname="127.0.0.1")
Ejemplo n.º 26
0
Archivo: engine.py Proyecto: jof/weewx
    def __init__(self, engine, config_dict):
        super(StdQC, self).__init__(engine, config_dict)

        # If the 'StdQC' or 'MinMax' sections do not exist in the configuration
        # dictionary, then an exception will get thrown and nothing will be
        # done.
        try:
            mm_dict = config_dict['StdQC']['MinMax']
        except KeyError:
            syslog.syslog(syslog.LOG_NOTICE, "engine: No QC information in config file.")
            return

        self.min_max_dict = {}

        target_unit_name = config_dict['StdConvert']['target_unit']
        target_unit = weewx.units.unit_constants[target_unit_name.upper()]
        converter = weewx.units.StdUnitConverters[target_unit]

        for obs_type in mm_dict.scalars:
            minval = float(mm_dict[obs_type][0])
            maxval = float(mm_dict[obs_type][1])
            if len(mm_dict[obs_type]) == 3:
                group = weewx.units._getUnitGroup(obs_type)
                vt = (minval, mm_dict[obs_type][2], group)
                minval = converter.convert(vt)[0]
                vt = (maxval, mm_dict[obs_type][2], group)
                maxval = converter.convert(vt)[0]
            self.min_max_dict[obs_type] = (minval, maxval)
        
        self.bind(weewx.NEW_LOOP_PACKET, self.new_loop_packet)
        self.bind(weewx.NEW_ARCHIVE_RECORD, self.new_archive_record)
Ejemplo n.º 27
0
Archivo: engine.py Proyecto: jof/weewx
    def setupStation(self, config_dict):
        """Set up the weather station hardware."""
        # Get the hardware type from the configuration dictionary. This will be
        # a string such as "VantagePro"
        stationType = config_dict['Station']['station_type']
    
        # Find the driver name for this type of hardware
        driver = config_dict[stationType]['driver']
        
        syslog.syslog(syslog.LOG_INFO, "engine: Loading station type %s (%s)" % (stationType, driver))

        # Import the driver:
        __import__(driver)
    
        # Open up the weather station, wrapping it in a try block in case
        # of failure.
        try:
            # This is a bit of Python wizardry. First, find the driver module
            # in sys.modules.
            driver_module = sys.modules[driver]
            # Find the function 'loader' within the module:
            loader_function = getattr(driver_module, 'loader')
            # Call it with the configuration dictionary as the only argument:
            self.console = loader_function(config_dict, self)
        except Exception, ex:
            # Signal that we have an initialization error:
            raise InitializationError(ex)
Ejemplo n.º 28
0
    def process_jobs(self):
        d = self.do_get(self.engine.address,
                        self.engine.port,
                        "/jobs",
                        self.engine.secret,
                        3)

        if d == None or d.get('status') == None or d.get('status') == "error":
            syslog.syslog(syslog.LOG_ERR,
                          "engine %s offline, disabling" % self.engine.name)
            self.enqueue({
                "item":   "engine",
                "action": "disable",
                "data":   self.engine
            })
            return False
        if not d.get('data'): return True

        self.enqueue({
            "item":   "job",
            "action": "handle",
            "active": 1,
            "engine": self.engine,
            "data":   d.get('data')
        })

        return True
Ejemplo n.º 29
0
def logprint(message,verbose=1,error_tuple=None):
    
  """
  |Print the message passed  and if the system is in debug mode or if the error is important send a mail
  |Remember, to clear syslog you could use :  > /var/log/syslog
  |To read system log in openwrt type:logread 

  """
# used like this:
#   except Exception as e:
#    message="""error in dataExchanged["cmd"]=="updateObjFromNode" """
#    logprint(message,verbose=10,error_tuple=(e,sys.exc_info()))

  message=str(message)

  if error_tuple!=None: 
    e=error_tuple[0]
    exc_type, exc_obj, exc_tb=error_tuple[1]
    fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
    #to print the message in the system log (to read system log in openwrt type:logread )
    message=message+", e:"+str(e.args)+str(exc_type)+str(fname)+" at line:"+str(exc_tb.tb_lineno)

  debug=1
  debug_level=0
  
  if verbose>debug_level or verbose>8:
    syslog.syslog(message) 
    print(message)
Ejemplo n.º 30
0
def update_invoices():
    """Identify invoices which have had a status of 1 (Pending)
    for longer than settings.PAYPAL_INVOICE_TIMEOUT
    and updates their status to 4 (Stale)
    
    This script is intended to be run from cron but can also by run manually
    
    The following crontab entry would run the script every 15 minutes:
    
    */15 * * * * /path/to/akvo/scripts/find_stale_invoices.py
    
    """
    log_message_prefix = 'AKVO RSR PAYPAL SUBSYSTEM: '
    stale_invoices = Invoice.objects.stale()
    if stale_invoices:
        for invoice in stale_invoices:
            original_status = invoice.get_status_display().lower()
            invoice.status = 4
            invoice.save()
            current_status = invoice.get_status_display().lower()
            message = 'Invoice %s status changed (%s -> %s).' % (
                invoice.id, original_status, current_status)
            sys.stdout.write(message + '\n')
            syslog(log_message_prefix + message)
    else:
        message = 'No stale invoices found.'
        sys.stdout.write(message + '\n')
        syslog(log_message_prefix + message)
Ejemplo n.º 31
0
def error(*args):
    print time.strftime("%Y-%m-%d %H:%M:%S") + ': ERROR:', ' '.join(args)
    syslog.syslog(syslog.LOG_ERR, ' '.join(args))
Ejemplo n.º 32
0
            print "\033[1;33m 实例%(port)s 数据库%(database)s 开始还原%(indir)s.....\033[0m" % parameter
            if os.path.isfile(indir):
                dbname = decompress(indir, check=True)
                rm("/data/mysql_restore_tmp/%s" % dbname, rf=True)
                decompress(indir, "/data/mysql_restore_tmp")
                indir = "/data/mysql_restore_tmp/%s" % dbname
                parameter["indir"] = indir

            if not database:
                cmd = """gawk -F':' 'NR == 3 && /Database:/{gsub(/ /,"",$NF);print $NF}' %(indir)s/*structure.sql""" % parameter
                old_database = os.popen(cmd).read().strip()
                if not old_database:
                    message = '"fail","不能获取要还原的数据库名"'
                    self.log.savelog(message)
                    self.errlog.savelog(message)
                    syslog.syslog(syslog.LOG_ERR, message)
                    raise IOError(message)
                parameter["database"] = old_database

            if datetime:
                check_line = tail("%s/structure.sql" % indir, 1)
                match = re.match(r"-- Dump completed on ([\s\d:-]+)",
                                 check_line[0])
                if not match:
                    raise ValueError("查找备份包/目录%s 的完成备份时间失败,请检查备份是否完整" % indir)
                backup_datetime = match.group(1).strip()
                try:
                    bin_log_sql = self.binlog_to_sql(datetime,
                                                     parameter["database"],
                                                     backup_datetime)
                    message = '"success","导出时间范围%s-%s的二进制日志到%s"' % (
Ejemplo n.º 33
0
def error(*args, sep=' ', end=''):
    # error is logged whatever the log level
    # ERROR WARN INFO DEBUG
    syslog.syslog(syslog.LOG_DEBUG, prunt(*args, sep=sep, end=end,level='ERROR'))
Ejemplo n.º 34
0
def generate_user_token(backends, mode):
    if mode == 'totp':
        gaus = totpcgi.utils.generate_secret(
            RATE_LIMIT, TOTP_WINDOW_SIZE, 5, bs=TOTP_KEY_LENGTH)

    else:
        gaus = totpcgi.utils.generate_secret(
            RATE_LIMIT, HOTP_WINDOW_SIZE, 5, bs=HOTP_KEY_LENGTH)
        gaus.set_hotp(0)

    user = os.environ['GL_USER']
    backends.secret_backend.save_user_secret(user, gaus, None)
    # purge all old state, as it's now obsolete
    backends.state_backend.delete_user_state(user)

    logger.info('New token generated for user %s' % user)
    remote_ip = os.environ['SSH_CONNECTION'].split()[0]
    syslog.syslog(
        syslog.LOG_NOTICE,
        'Enrolled: user=%s, host=%s, mode=%s' % (user, remote_ip, mode)
    )

    if mode == 'totp':
        # generate provisioning URI
        tpt = Template(TOTP_USER_MASK)
        totp_user = tpt.safe_substitute(username=user)
        qr_uri = gaus.otp.provisioning_uri(totp_user)
        import urllib
        print('')
        print('Please make sure "qrencode" is installed.')
        print('Run the following commands to display your QR code:')
        print('    unset HISTFILE')
        print('    qrencode -tANSI -m1 -o- "%s"' % qr_uri)
        print('')
        print('If that does not work or if you do not have access to')
        print('qrencode or a similar QR encoding tool, then you may')
        print('open an INCOGNITO/PRIVATE MODE window in your browser')
        print('and paste the following URL:')
        print(
            'https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=%s' %
            urllib.quote_plus(qr_uri))
        print('')
        print('Scan the resulting QR code with your TOTP app, such as')
        print('FreeOTP (recommended), Google Authenticator, Authy, or others.')

    else:
        import binascii
        import base64
        keyhex = binascii.hexlify(base64.b32decode(gaus.otp.secret))
        print('')
        print('Please make sure "ykpersonalize" has been installed.')
        print('Insert your yubikey and, as root, run the following command')
        print('to provision the secret into slot 1 (use -2 for slot 2):')
        print('    unset HISTFILE')
        print('    ykpersonalize -1 -ooath-hotp -oappend-cr -a%s' % keyhex)
        print('')

    if gaus.scratch_tokens:
        print('Please write down/print the following 8-digit scratch tokens.')
        print('If you lose your device or temporarily have no access to it, you')
        print('will be able to use these tokens for one-time bypass.')
        print('')
        print('Scratch tokens:')
        print('\n'.join(gaus.scratch_tokens))

    print

    print('Now run the following command to verify that all went well')

    if mode == 'totp':
        print('    %s val [token]' % GL_2FA_COMMAND)
    else:
        print('    %s val [yubkey button press]' % GL_2FA_COMMAND)

    print_help_link()
Ejemplo n.º 35
0
            status = "%s uses 'override'. It's super effective!" % user
            syslog.syslog(
                syslog.LOG_NOTICE, 'OVERRIDE USED: user=%s, host=%s'
            )
        else:
            logger.critical('Failed to validate token.')
            print('If using a phone app, please wait for token to change before trying again.')
            syslog.syslog(
                syslog.LOG_NOTICE,
                'Failure: user=%s, host=%s, message=%s' % (user, remote_ip, str(ex))
            )
            print_help_link()
            sys.exit(1)

    syslog.syslog(
        syslog.LOG_NOTICE,
        'Success: user=%s, host=%s, message=%s' % (user, remote_ip, status)
    )
    logger.info(status)

    # Okay, deleting
    logger.info('Removing the secrets file.')
    backends.secret_backend.delete_user_secret(user)
    # purge all old state, as it's now obsolete
    logger.info('Cleaning up state files.')
    backends.state_backend.delete_user_state(user)
    logger.info('Expiring all validations.')
    inval(expire_all=True)

    logger.info('You have been successfully unenrolled.')

Ejemplo n.º 36
0
def logmsg(level, msg):
    syslog.syslog(
        level, 'station: {}: {}'.format(threading.currentThread().getName(),
                                        msg))
Ejemplo n.º 37
0
import syslog
syslog.openlog(ident="LOG_IDENTIFIER",
               logoption=syslog.LOG_PID,
               facility=syslog.LOG_LOCAL0)
syslog.syslog('Log processing initiated...')
Ejemplo n.º 38
0
def get_cpu_info():
    # Number of cores
    num_cpu_cores = cpu_count()

    new_compute_data["cpu"] = {}

    new_compute_data["cpu"]["cpu_num"] = num_cpu_cores

    # CPU type
    proc_info_file = open("/proc/cpuinfo", "r")

    for line in proc_info_file:
        line = line.rstrip()

        model_match = re.match("^model name\s+:\s+(.*)$", line)

        if model_match:
            cpu_type = re.sub("\s+", " ", model_match.group(1))

            new_compute_data["cpu"]["cpu_type"] = cpu_type

            break

    proc_info_file.close()

    # Hyperthreading info
    # Skip Interlagos nodes
    if any(lower <= int(node) <= upper for (lower, upper) in [(325, 378)]):
        sys.stdout.write("Hyperthreading: n/a\n")

        new_compute_data["cpu"]["hyperthreading"] = False

    else:
        proc_info_file = open("/proc/cpuinfo", "r")

        for line in proc_info_file:
            line = line.rstrip()

            if re.search("^siblings", line) is not None:
                num_siblings = line.split()[2]

            elif re.search("^cpu cores", line) is not None:
                num_cores = line.split()[3]

                break

        proc_info_file.close()

        num_siblings = int(num_siblings)
        num_cores = int(num_cores)

        if num_cores == num_siblings:
            new_compute_data["cpu"]["hyperthreading"] = False

        else:
            syslog.syslog(
                syslog.LOG_ERR, "NOC-NETCOOL-TICKET: Node " + str(node) +
                " has hyperthreading enabled")

            new_compute_data["cpu"]["hyperthreading"] = True

    sys.stdout.write("CPU:\n")
    sys.stdout.write("     CPU Type: " + cpu_type + "\n")
    sys.stdout.write("     CPU Cores: " + str(num_cpu_cores) + "\n")
    if new_compute_data["cpu"]["hyperthreading"] is False:
        sys.stdout.write("     Hyperthreading: ok (disabled)\n")

    else:
        sys.stdout.write(red + "     Hyperthreading: Error (enabled)\n" +
                         endcolor)

    return None
Ejemplo n.º 39
0
def clean_scratch():
    # Loop through every directory in /scratch
    for each_dir in glob.glob("/scratch/*"):
        #print "Checking " + each_dir

        # Skip things we don't care about
        if os.path.isdir(each_dir) is False:
            continue

        if each_dir == "/scratch/lost+found":
            continue

        if re.search("^/scratch/[0-9]", each_dir) is None:
            continue

        job_id = re.sub("/scratch/", "", each_dir)

        signal.alarm(30)

        # Is this job still running?
        try:
            qstat_info = subprocess.Popen([main_config["qstat"], job_id],
                                          stdin=None,
                                          stdout=subprocess.PIPE,
                                          stderr=subprocess.PIPE)
            out, err = qstat_info.communicate()
            status = qstat_info.wait()

            signal.alarm(0)

        except Alarm:
            sys.stderr.write("/scratch cleanup check of '" + each_dir +
                             "': Timeout\n")

        if re.search("Unknown Job Id", err) is not None:
            job_running = False

        else:
            if status != 0:
                sys.stderr.write(err + "\n")
                sys.stderr.write(
                    "Non-zero exit status of `qstat` detected, skipping directory.\n"
                )
                continue

            job_running = True

        # If the job is running, how old is this directory?  Get the latest mtime from the data inside the directory to find out.
        if job_running is False:
            highest_mtime = 0

            for root, dirs, files in os.walk(each_dir):
                mtime = int(os.stat(root).st_mtime)

                if mtime > highest_mtime:
                    highest_mtime = mtime

                for each_file in files:
                    mtime = int(
                        os.stat(os.path.join(root, each_file)).st_mtime)

                    if mtime > highest_mtime:
                        highest_mtime = mtime

            # If the highest mtime is over 24 hours ago, consider the data stale
            time_diff = time.time() - highest_mtime
            if time_diff > (60 * 60 * 24):
                print "Beomon detected possible stale /scratch data at '" + each_dir + "'"
                syslog.syslog(
                    syslog.LOG_INFO,
                    "Beomon detected possible stale /scratch data at '" +
                    each_dir + "'")
Ejemplo n.º 40
0
def log(*args):
    print time.strftime("%Y-%m-%d %H:%M:%S") + ':', ' '.join(args)
    syslog.syslog(syslog.LOG_INFO, ' '.join(args))
Ejemplo n.º 41
0
 def emit(self, record):
     msg = self.format(record)
     priority = self._map_priority(record.levelno)
     syslog.syslog(priority, msg)
Ejemplo n.º 42
0
def kill_old_processes():
    user_processes = {}
    lingering_processes = {}

    for pid_dir in glob.glob("/proc/*"):
        # Skip things that are not PID directories
        try:
            pid = pid_dir.split("/")[2]

        except IndexError:
            continue

        try:
            int(pid)

        except ValueError:
            continue

        # The process could go away during this section, that's ok just move on to the next one
        try:
            proc_status_data = open("/proc/" + pid + "/status").read()

        except IOError:
            continue

        # Find the process name and UID it is running as
        for line in proc_status_data.split(os.linesep):
            process_name_line_match = re.match("Name:\s+(.+)", line)

            if process_name_line_match is not None:
                process_name = process_name_line_match.group(1)

            uid_line_match = re.match("Uid:\s+([0-9]+)\s+", line)

            if uid_line_match is not None:
                uid = uid_line_match.group(1)
                break

        # Skip system users
        if int(uid) < 1000:
            continue

        # Get the username from the UID
        try:
            username = pwd.getpwuid(int(uid))[0]

        except KeyError:
            fatal_error("Unable to determine username of UID " + uid, None)

        if username not in user_processes:
            user_processes[username] = {}

        user_processes[username][pid] = process_name

    # Loop through every user running a process and see if they are running a job on this node
    for user in user_processes:
        #print "Checking for possible lingering processes of user " + user

        signal.alarm(60)

        # Is the user running on job on this node?
        try:
            qstat_info = subprocess.Popen(
                [main_config["qstat"], "-n", "-u", user],
                stdin=None,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE)
            qstat_out, qstat_err = qstat_info.communicate()
            status = qstat_info.wait()

            signal.alarm(0)

            if status != 0:
                sys.stderr.write(
                    "Non-zero exit status of `qstat` detected, skipping user.\n"
                )
                continue

        except Alarm:
            sys.stderr.write("Failed to check processes of user '" + user +
                             "': Timeout\n")

        job_active = False
        for line in qstat_out.split(os.linesep):
            if re.search("\s+" + hostname + "/",
                         line) is not None or re.search(
                             "\+" + hostname + "/", line) is not None:
                job_active = True
                break

        if job_active is False:
            syslog.syslog(
                syslog.LOG_INFO,
                "Beomon detected suspected lingering process(es) of user '" +
                user + "':" + str(user_processes[user]))

            print "Found suspected lingering process(es) of user '" + user + "':"

            lingering_processes[user] = user_processes[user]

            for pid in user_processes[user]:
                print "     " + pid + " : " + user_processes[user][pid]

    new_compute_data["lingering_processes"] = lingering_processes
Ejemplo n.º 43
0
def log_error(msg):
    syslog.syslog(syslog.LOG_ERR, msg)
    if DEBUG: print msg
Ejemplo n.º 44
0
 def log(self, entry):
     """ This method will log information to the local syslog facility """
     if self.logging:
         syslog.openlog('ansible-%s' % self.module._name)
         syslog.syslog(syslog.LOG_NOTICE, entry)
Ejemplo n.º 45
0
                   syslog.LOG_LOCAL5)

    base_url = config.get('routing', 'base_url')
    hours = sorted(config.get('routing', 'update_hours').split())
    prefix = config.get('routing', 'prefix_basename')
    suffix = config.get('routing', 'suffix_basename')

    current_date = None
    while 1:
        try:
            current_date = datetime.date.today()
            # Initialization of the URL to fetch
            dir = current_date.strftime("%Y.%m")
            file_day = current_date.strftime("%Y%m%d")
            daily_url = base_url + '/' + dir + '/' + prefix + file_day + '.%s' + suffix

            for hour in reversed(hours):
                url = daily_url % hour
                if checkURL(url):
                    if not already_downloaded(file_day, hour):
                        syslog.syslog(syslog.LOG_INFO,
                                      "New bview file found: " + url)
                        downloadURL(url)
                        last_hour = hour
                        break
        except:
            syslog.syslog(
                syslog.LOG_CRIT,
                'Unable to download bview file. Server does not respond.')
        time.sleep(sleep_timer)
Ejemplo n.º 46
0
#!/usr/bin/env python3
import sys
import os

PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(
    os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))

import syslog
from client.matrix_connection import MatrixConnection
from client.mpd import get_cover

if __name__ == "__main__":
    try:
        matrix = MatrixConnection([32, 32])
        matrix.show(get_cover())
    except Exception as e:
        syslog.syslog(syslog.LOG_INFO, str(e))
Ejemplo n.º 47
0
def logmsg(level, msg):
    syslog.syslog(level, '[wf-udp-listener]: %s' % msg)
Ejemplo n.º 48
0
def log_info(msg):
    syslog.syslog(syslog.LOG_INFO, msg)
    if DEBUG: print msg
Ejemplo n.º 49
0
    def _statsHTMLTable(self,
                        table_options,
                        table_stats,
                        table_name,
                        NOAA=False):
        """
        table_options: Dictionary containing skin.conf options for particluar table
        all_stats: Link to all_stats TimespanBinder
        """

        bgColours = zip(table_options['minvalues'], table_options['maxvalues'],
                        table_options['colours'])

        if NOAA is True:
            unit_formatted = ""
        else:
            obs_type = table_options['obs_type']
            aggregate_type = table_options['aggregate_type']
            converter = table_stats.converter

            # obs_type
            readingBinder = getattr(table_stats, obs_type)

            # Some aggregate come with an argument
            if aggregate_type in ['max_ge', 'max_le', 'min_le', 'sum_ge']:

                try:
                    threshold_value = float(
                        table_options['aggregate_threshold'][0])
                except KeyError:
                    syslog.syslog(
                        syslog.LOG_INFO,
                        "%s: Problem with aggregate_threshold. Should be in the format: [value], [units]"
                        % (os.path.basename(__file__)))
                    return "Could not generate table %s" % table_name

                threshold_units = table_options['aggregate_threshold'][1]

                try:
                    reading = getattr(readingBinder, aggregate_type)(
                        (threshold_value, threshold_units))
                except IndexError:
                    syslog.syslog(
                        syslog.LOG_INFO,
                        "%s: Problem with aggregate_threshold units: %s" %
                        (os.path.basename(__file__), str(threshold_units)))
                    return "Could not generate table %s" % table_name
            else:
                try:
                    reading = getattr(readingBinder, aggregate_type)
                except KeyError:
                    syslog.syslog(
                        syslog.LOG_INFO, "%s: aggregate_type %s not found" %
                        (os.path.basename(__file__), aggregate_type))
                    return "Could not generate table %s" % table_name

            unit_type = reading.converter.group_unit_dict[reading.value_t[2]]

            unit_formatted = ''

            # 'units' option in skin.conf?
            if 'units' in table_options:
                unit_formatted = table_options['units']
            else:
                if (unit_type == 'count'):
                    unit_formatted = "Days"
                else:
                    if unit_type in reading.formatter.unit_label_dict:
                        unit_formatted = reading.formatter.unit_label_dict[
                            unit_type]

            # For aggregrate types which return number of occurrences (e.g. max_ge), set format to integer

            # Don't catch error here - we absolutely need the string format
            if unit_type == 'count':
                format_string = '%d'
            else:
                format_string = reading.formatter.unit_format_dict[unit_type]

        htmlText = '<table class="table">'
        htmlText += "    <thead>"
        htmlText += "        <tr>"
        htmlText += "        <th>%s</th>" % unit_formatted

        for mon in table_options.get('monthnames', [
                'Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago', 'Set',
                'Ott', 'Nov', 'Dic'
        ]):
            htmlText += "        <th>%s</th>" % mon

        htmlText += "    </tr>"
        htmlText += "    </thead>"
        htmlText += "    <tbody>"

        for year in table_stats.years():
            year_number = datetime.fromtimestamp(year.timespan[0]).year

            htmlLine = (' ' * 8) + "<tr>\n"

            if NOAA is True:
                htmlLine += (' ' * 12) + "%s\n" % \
                                         self._NoaaYear(datetime.fromtimestamp(year.timespan[0]), table_options)
            else:
                htmlLine += (' ' * 12) + "<td>%d</td>\n" % year_number

            for month in year.months():
                if NOAA is True:
                    #for property, value in vars(month.dateTime.value_t[0]).iteritems():
                    #    print property, ": ", value

                    if (month.timespan[1] < table_stats.timespan.start) or (
                            month.timespan[0] > table_stats.timespan.stop):
                        # print "No data for... %d, %d" % (year_number, datetime.fromtimestamp(month.timespan[0]).month)
                        htmlLine += "<td>-</td>\n"
                    else:
                        htmlLine += self._NoaaCell(
                            datetime.fromtimestamp(month.timespan[0]),
                            table_options)
                else:
                    if unit_type == 'count':
                        try:
                            value = getattr(getattr(month, obs_type),
                                            aggregate_type)(
                                                (threshold_value,
                                                 threshold_units)).value_t
                        except:
                            value = [0, 'count']
                    else:
                        value = converter.convert(
                            getattr(getattr(month, obs_type),
                                    aggregate_type).value_t)

                    htmlLine += (' ' * 12) + self._colorCell(
                        value[0], format_string, bgColours)

            htmlLine += (' ' * 8) + "</tr>\n"

            htmlText += htmlLine

#extra </tr> that's not needed
#htmlText += (' ' * 8) + "</tr>\n"
        htmlText += (' ' * 4) + "</tbody>\n"
        htmlText += "</table>\n"

        return htmlText
Ejemplo n.º 50
0
def log_err(err):
    print(err, file=sys.stderr)
    syslog.syslog(syslog.LOG_USER | syslog.LOG_ERR, "%s: %s" % (sys.argv[0], err))
Ejemplo n.º 51
0
def file_presend(sock):
    syslog.syslog(syslog.LOG_INFO, "PRE_SEND EXECUTED")
Ejemplo n.º 52
0
def main():
    server = SocketServer.SocketServer()
    bio = BioControle.BioControle()

    pump_duration = 300
    fan_duration = 200
    circ_duration = 1800

    # Pump schedule
    schedule.every().day.at("08:00").do(run_threaded,
                                        bio.run_pump,
                                        run_time=pump_duration)
    schedule.every().day.at("13:00").do(run_threaded,
                                        bio.run_pump,
                                        run_time=pump_duration)
    schedule.every().day.at("18:00").do(run_threaded,
                                        bio.run_pump,
                                        run_time=pump_duration)
    #schedule.every().day.at("19:25").do(run_threaded, bio.run_pump, run_time=pump_duration)
    # Fan schedule
    schedule.every(2).hours.do(run_threaded,
                               bio.run_fan,
                               run_time=fan_duration)
    # Circulation pump schedule
    schedule.every().day.at("07:45").do(run_threaded,
                                        bio.run_circulate,
                                        run_time=circ_duration)
    schedule.every().day.at("12:45").do(run_threaded,
                                        bio.run_circulate,
                                        run_time=circ_duration)
    schedule.every().day.at("17:45").do(run_threaded,
                                        bio.run_circulate,
                                        run_time=circ_duration)

    # Job display schedule
    #schedule.every(15).minutes.do(display_jobs)
    display_jobs()

    date_time = datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
    syslog.syslog('%s: Server Ready ' % (date_time))
    print('%s: Server Ready ' % (date_time))

    sleepTimer = 10
    while True:

        try:
            schedule.run_pending()

            try:
                (data, client_sock) = server.check_select()
                if data:
                    process_request(data, server, client_sock, bio)
                    server.close_client(client_sock)

            except:
                pass

            time.sleep(sleepTimer)
            BioControle.userled.toggle()

        except (KeyboardInterrupt, SystemExit):
            cleanup()
            exit()
Ejemplo n.º 53
0
def file_postsend(sock):
    syslog.syslog(syslog.LOG_INFO, "POST_SEND EXECUTED")
Ejemplo n.º 54
0
    def get_extension_list(self, valid_timespan, db_lookup):
        """For weewx V3.x extensions. Should return a list
        of objects whose attributes or keys define the extension.

        valid_timespan:  An instance of weeutil.weeutil.TimeSpan. This will hold the
        start and stop times of the domain of valid times.

        db_lookup: A function with call signature db_lookup(data_binding), which
        returns a database manager and where data_binding is an optional binding
        name. If not given, then a default binding will be used.
        """

        # Time to recalculate?
        if (time.time() - (self.refresh_interval * 60)) > self.cache_time:
            self.cache_time = time.time()

            #
            # The all time statistics
            #

            # If this generator has been called in the [SummaryByMonth] or [SummaryByYear]
            # section in skin.conf then valid_timespan won't contain enough history data for
            # the colourful summary tables.
            alltime_timespan = weeutil.weeutil.TimeSpan(
                db_lookup().first_timestamp,
                db_lookup().last_timestamp)

            # First, get a TimeSpanStats object for all time. This one is easy
            # because the object valid_timespan already holds all valid times to be
            # used in the report.
            all_stats = TimespanBinder(alltime_timespan,
                                       db_lookup,
                                       formatter=self.generator.formatter,
                                       converter=self.generator.converter)

            # Now create a small dictionary with keys 'alltime' and 'seven_day':
            self.search_list_extension['alltime'] = all_stats

            #
            #  The html history tables
            #
            t1 = time.time()
            ngen = 0

            for table in self.table_dict.sections:
                noaa = True if table == 'NOAA' else False

                table_options = weeutil.weeutil.accumulateLeaves(
                    self.table_dict[table])

                # Show all time unless starting date specified
                startdate = table_options.get('startdate', None)
                if startdate is not None:
                    table_timespan = weeutil.weeutil.TimeSpan(
                        int(startdate),
                        db_lookup().last_timestamp)
                    table_stats = TimespanBinder(
                        table_timespan,
                        db_lookup,
                        formatter=self.generator.formatter,
                        converter=self.generator.converter)
                else:
                    table_stats = all_stats

                table_name = table + '_table'
                self.search_list_extension[table_name] = self._statsHTMLTable(
                    table_options, table_stats, table_name, NOAA=noaa)
                ngen += 1

            t2 = time.time()

            syslog.syslog(
                syslog.LOG_INFO, "%s: Generated %d tables in %.2f seconds" %
                (os.path.basename(__file__), ngen, t2 - t1))

        return [self.search_list_extension]
Ejemplo n.º 55
0
def getSpider(url, api, header='', **options):
    req = ''
    for idx, op in enumerate(options):
        if idx == 0:
            req += '?' + op + '=' + str(options[op])
        else:
            req += '&' + op + '=' + str(options[op])
    resp = requests.get(url + req, auth=(api, ''))
    return resp


#
# Get 5 most recent jobs
#
syslog.syslog("ScrapingHub: starting...")
syslog.syslog("ScrapingHub: Getting jobs info")
try:
    res_jobs = getSpider(url_jobs,
                         API_key,
                         project=PRJ,
                         state='finished',
                         count=5)
except (requests.HTTPError, ConnectionError):
    syslog.syslog("ScrapingHub: Connection error for jobs info")
    print("Connection Error!")
    sys.exit(1)
json_job = res_jobs.json()
# Find latest job
max_time = 0
max_time_id = -1
Ejemplo n.º 56
0
def file_callback(session, node, edge, sock):
    syslog.syslog(syslog.LOG_INFO, "CALLBACK EXECUTED")
Ejemplo n.º 57
0
def clean_loop():
    syslog.syslog(syslog.LOG_AUTH, "Closing /dev/loop0")
    os.system("sudo losetup -d /dev/loop0")
Ejemplo n.º 58
0
def log(msg):
    print msg
    syslog.syslog(msg)
Ejemplo n.º 59
0
def close_container():
    syslog.syslog(syslog.LOG_AUTH, "Closing container")
    os.system("cryptsetup luksClose " + current_login + "_tmp")
Ejemplo n.º 60
0
def pam_sm_end(pamh):
    syslog.syslog(syslog.LOG_AUTH, "Closing Pamela Ressources...")
    umount_container()
    close_container()
    clean_loop()
    return pamh.PAM_SUCCESS