syslog.LOG_PID

Here are the examples of the python api syslog.LOG_PID taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

30 Examples 7

Example 1

Project: firewalld
Source File: logger.py
View license
    def __init__(self):
        # Only initialize LogTarget here as fs should be None
        LogTarget.__init__(self)
        #
        # Derived from: https://github.com/canvon/firewalld/commit/af0edfee1cc1891b7b13f302ca5911b24e9b0f13
        #
        # Work around Python issue 27875, "Syslogs /usr/sbin/foo as /foo
        # instead of as foo"
        # (but using openlog explicitly might be better anyway)
        #
        # Set ident to basename, log PID as well, and log to facility "daemon".
        syslog.openlog(os.path.basename(sys.argv[0]),
                       syslog.LOG_PID, syslog.LOG_DAEMON)

Example 2

View license
def main(smp):
	try:
		arg          = {}
		arg["opt"]   = ['-g','raw']
		vap = varnishapi.VarnishLog(**arg)
		if vap.error:
			print(vap.error)
			exit(1)
		smp.execute(vap)
	except KeyboardInterrupt:
		vap.Fini()
	except Exception as e:
		syslog.openlog(sys.argv[0], syslog.LOG_PID|syslog.LOG_PERROR, syslog.LOG_LOCAL0)
		syslog.syslog(syslog.LOG_ERR, traceback.format_exc())

Example 3

Project: varnishHostStat
Source File: varnishhoststat.py
View license
def main(opts):
	try:
		vhs = varnishhoststatcore.varnishHostStat(opts)
		vhs.execute()
	except KeyboardInterrupt:
		pass
	except Exception as e:
		syslog.openlog(sys.argv[0], syslog.LOG_PID|syslog.LOG_PERROR, syslog.LOG_LOCAL0)
		syslog.syslog(syslog.LOG_ERR, traceback.format_exc())

Example 4

Project: vsltrans
Source File: vsltrans.py
View license
def main(opts):
	try:
		vhs = vsltranscore.vslTrans4(opts)
		vhs.execute()
	except KeyboardInterrupt:
		pass
	except Exception as e:
		syslog.openlog(sys.argv[0], syslog.LOG_PID|syslog.LOG_PERROR, syslog.LOG_LOCAL0)
		syslog.syslog(syslog.LOG_ERR, traceback.format_exc())

Example 5

Project: tweetsniff
Source File: tweetsniff.py
View license
def writeLog(msg):

	"""Output a message to the console/Syslog depending on the host"""

	if os.name == "posix":
        	syslog.openlog(logoption=syslog.LOG_PID,facility=syslog.LOG_MAIL)
        	syslog.syslog(msg)
	else:
		print msg
        return

Example 6

Project: amun
Source File: log_syslog.py
View license
	def incoming(self, attackerIP, attackerPort, victimIP, victimPort, vulnName, timestamp, downloadMethod, loLogger, attackerID, shellcodeName):
		try:
			self.log_obj = amun_logging.amun_logging("log_syslog", loLogger)
			syslog_message = "Exploit: %s -> %s:%s %s (%s)" % (attackerIP,victimIP,victimPort,vulnName,downloadMethod)
			syslog.openlog('Amun',syslog.LOG_PID,syslog.LOG_LOCAL4)
			syslog.syslog(syslog.LOG_WARNING, syslog_message)
			syslog.closelog()
		except KeyboardInterrupt:
			raise

Example 7

Project: acoustid-server
Source File: utils.py
View license
    def __init__(self, ident=None, facility=syslog.LOG_USER, log_pid=False):
        Handler.__init__(self)
        self.facility = facility
        if isinstance(facility, basestring):
            self.facility = self.facility_names[facility]
        options = 0
        if log_pid:
            options |= syslog.LOG_PID
        syslog.openlog(ident, options, self.facility)
        self.formatter = None

Example 8

Project: FuzzLabs
Source File: DatabaseHandler.py
View license
    def __init__(self, config = None, root = None):

        if config == None or root == None:
            return

        self.config   = config
        self.root     = root
        self.dbclient = MongoClient(self.config['general']['database'])
        self.database = self.dbclient.engine
        syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_DAEMON)

Example 9

Project: FuzzLabs
Source File: DatabaseThread.py
View license
    def __init__(self, root, config, data_queue):
        threading.Thread.__init__(self)
        self.root = root
        self.config = config
        self.dqueue = data_queue
        self.running = True
        syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_DAEMON)

Example 10

Project: FuzzLabs
Source File: EngineThread.py
View license
    def __init__(self, thread_queue, root, config, data_queue, engine):
        threading.Thread.__init__(self)
        self.root         = root
        self.config       = config
        self.dqueue       = data_queue
        self.engine       = engine
        self.thread_queue = thread_queue
        self.running      = True
        syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_DAEMON)

Example 11

Project: pygopherd
Source File: logger.py
View license
def init(config):
    global log, priority, facility, syslogfunc
    logmethod = config.get("logger", "logmethod")
    if logmethod == "syslog":
        import syslog
        priority = eval("syslog." + config.get("logger", "priority"))
        facility = eval("syslog." + config.get("logger", "facility"))
        syslog.openlog('pygopherd', syslog.LOG_PID, facility)
        syslogfunc = syslog.syslog
        log = log_syslog
    elif logmethod == 'file':
        log = log_file
    else:
        log = log_none

Example 12

Project: pygopherd
Source File: logger.py
View license
def init(config):
    global log, priority, facility, syslogfunc
    logmethod = config.get("logger", "logmethod")
    if logmethod == "syslog":
        import syslog
        priority = eval("syslog." + config.get("logger", "priority"))
        facility = eval("syslog." + config.get("logger", "facility"))
        syslog.openlog('pygopherd', syslog.LOG_PID, facility)
        syslogfunc = syslog.syslog
        log = log_syslog
    elif logmethod == 'file':
        log = log_file
    else:
        log = log_none

Example 13

Project: clonedigger
Source File: logger.py
View license
    def __init__(self, threshold, sid=None, encoding='UTF-8'):
        import syslog
        AbstractLogger.__init__(self, threshold)
        if sid is None:
            sid = 'syslog'
        self.encoding = encoding
        syslog.openlog(sid, syslog.LOG_PID)

Example 14

Project: clonedigger
Source File: logger.py
View license
    def __init__(self, threshold, sid=None, encoding='UTF-8'):
        import syslog
        AbstractLogger.__init__(self, threshold)
        if sid is None:
            sid = 'syslog'
        self.encoding = encoding
        syslog.openlog(sid, syslog.LOG_PID)

Example 15

Project: b2bua
Source File: SipLogger.py
View license
    def safe_open(self):
        try:
            syslog.openlog(self.app, syslog.LOG_PID)
        except Exception, e:
            print e

Example 16

Project: python-pyhsm
Source File: yubikey_ksm.py
View license
def main():
    """
    Main program.
    """
    my_name = os.path.basename(sys.argv[0])
    if not my_name:
        my_name = "yhsm-yubikey-ksm"
    syslog.openlog(my_name, syslog.LOG_PID, syslog.LOG_LOCAL0)

    args = parse_args()
    args_fixup(args)

    aead_backend = None
    if args.db_url:
        # Using an SQL database for AEADs
        try:
            aead_backend = SQLBackend(args.db_url)
        except Exception as e:
            my_log_message(args.debug or args.verbose, syslog.LOG_ERR,
                           'Could not connect to database "%s" : %s' % (args.db_url, e))
            return 1
    else:
        # Using the filesystem for AEADs
        try:
            aead_backend = FSBackend(args.aead_dir, args.key_handles)
        except Exception as e:
            my_log_message(args.debug or args.verbose, syslog.LOG_ERR,
                           'Could not create AEAD FSBackend: %s' % e)
            return 1

    if args.device == '-':
        # Using a soft-HSM with keys from stdin
        try:
            hsm = SoftYHSM.from_json(sys.stdin.read(), debug=args.debug)
        except ValueError as e:
            my_log_message(args.debug or args.verbose, syslog.LOG_ERR,
                           'Failed opening soft YHSM from stdin : %s' % (e))
            return 1
    elif os.path.isfile(args.device):
        # Using a soft-HSM from file
        try:
            hsm = SoftYHSM.from_file(args.device, debug=args.debug)
        except ValueError as e:
            my_log_message(args.debug or args.verbose, syslog.LOG_ERR,
                           'Failed opening soft YHSM "%s" : %s' % (args.device, e))
            return 1
    else:
        # Using a real HSM
        try:
            hsm = pyhsm.YHSM(device=args.device, debug=args.debug)
            context.files_preserve = [hsm.get_raw_device()]
        except serial.SerialException as e:
            my_log_message(args.debug or args.verbose, syslog.LOG_ERR,
                           'Failed opening YubiHSM device "%s" : %s' % (args.device, e))
            return 1

    if args.daemon:
        with context:
            run(hsm, aead_backend, args)
    else:
        try:
            run(hsm, aead_backend, args)
        except KeyboardInterrupt:
            print ""
            print "Shutting down"
            print ""

Example 17

Project: python-pyhsm
Source File: validation_server.py
View license
def main():
    """
    The main function that will be executed when running this as a stand alone script.
    """
    my_name = os.path.basename(sys.argv[0])
    if not my_name:
        my_name = "yhsm-validation-server"
    syslog.openlog(my_name, syslog.LOG_PID, syslog.LOG_LOCAL0)

    global args
    args = parse_args()
    args_fixup()

    global hsm
    try:
        hsm = pyhsm.YHSM(device = args.device, debug = args.debug)
    except serial.SerialException, e:
        my_log_message(args, syslog.LOG_ERR, 'Failed opening YubiHSM device "%s" : %s' %(args.device, e))
        return 1

    write_pid_file(args.pid_file)

    try:
        run()
    except KeyboardInterrupt:
        print ""
        print "Shutting down"
        print ""

Example 18

Project: FuzzLabs
Source File: CollectorDaemon.py
View license
    def __init__(self, root, config):
        """
        Initialize daemon.

        @type  root:     String
        @param root:     Full path to the root directory
        @type  config:   Dictionary
        @param config:   The complete configuration as a dictionary
        """

        self.root            = root
        self.config          = config
        self.modules         = None
        self.thread_queue    = []
        self.stdin_path      = self.config['daemon']['stdin']
        self.stdout_path     = self.config['daemon']['stdout']
        self.stderr_path     = self.config['daemon']['stderr']
        self.pidfile_path    = self.config['daemon']['pidfile']
        self.pidfile_timeout = self.config['daemon']['pidfile_timeout']
        self.running         = True
        syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_DAEMON)

Example 19

Project: karaka
Source File: common.py
View license
def openlog():
    syslog.openlog("karaka %s" % os.path.basename(sys.argv[0]), syslog.LOG_PID)

Example 20

Project: karaka
Source File: common.py
View license
def openlog():
    syslog.openlog("karaka %s" % os.path.basename(sys.argv[0]), syslog.LOG_PID)

Example 21

Project: neubot
Source File: macos.py
View license
def main(args):

    ''' Notify the user '''

    try:
        options, arguments = getopt.getopt(args[1:], 'f:')
    except getopt.error:
        sys.exit('Usage: neubot notifier [-f database]\n')
    if arguments:
        sys.exit('Usage: neubot notifier [-f database]\n')

    database = utils_hier.DATABASEPATH
    for name, value in options:
        if name == '-f':
            database = value

    syslog.openlog('neubot_notify', syslog.LOG_PID, syslog.LOG_USER)

    # Give Neubot time to start
    time.sleep(15)

    uri = __should_adjust_privacy(database)
    if uri:
        __notify_adjust_privacy(uri)

Example 22

Project: neubot
Source File: unix.py
View license
def main(args):

    ''' Notify the user '''

    try:
        options, arguments = getopt.getopt(args[1:], 'f:')
    except getopt.error:
        sys.exit('Usage: neubot notifier [-f database]\n')
    if arguments:
        sys.exit('Usage: neubot notifier [-f database]\n')

    database = utils_hier.DATABASEPATH
    for name, value in options:
        if name == '-f':
            database = value

    syslog.openlog('neubot_notify', syslog.LOG_PID, syslog.LOG_USER)

    while True:
        if __should_adjust_privacy(database):
            __notify_adjust_privacy()
            privacy_interval = SHORT_PRIVACY_INTERVAL
        else:
            privacy_interval = LONG_PRIVACY_INTERVAL

        time.sleep(privacy_interval)

Example 23

Project: neubot
Source File: macos.py
View license
def main(args):

    ''' Notify the user '''

    try:
        options, arguments = getopt.getopt(args[1:], 'f:')
    except getopt.error:
        sys.exit('Usage: neubot notifier [-f database]\n')
    if arguments:
        sys.exit('Usage: neubot notifier [-f database]\n')

    database = utils_hier.DATABASEPATH
    for name, value in options:
        if name == '-f':
            database = value

    syslog.openlog('neubot_notify', syslog.LOG_PID, syslog.LOG_USER)

    # Give Neubot time to start
    time.sleep(15)

    uri = __should_adjust_privacy(database)
    if uri:
        __notify_adjust_privacy(uri)

Example 24

Project: neubot
Source File: unix.py
View license
def main(args):

    ''' Notify the user '''

    try:
        options, arguments = getopt.getopt(args[1:], 'f:')
    except getopt.error:
        sys.exit('Usage: neubot notifier [-f database]\n')
    if arguments:
        sys.exit('Usage: neubot notifier [-f database]\n')

    database = utils_hier.DATABASEPATH
    for name, value in options:
        if name == '-f':
            database = value

    syslog.openlog('neubot_notify', syslog.LOG_PID, syslog.LOG_USER)

    while True:
        if __should_adjust_privacy(database):
            __notify_adjust_privacy()
            privacy_interval = SHORT_PRIVACY_INTERVAL
        else:
            privacy_interval = LONG_PRIVACY_INTERVAL

        time.sleep(privacy_interval)

Example 25

Project: neubot
Source File: system_posix.py
View license
def get_background_logger():
    ''' Return the background logger '''
    syslog.openlog("neubot", syslog.LOG_PID, syslog.LOG_DAEMON)
    return __logger

Example 26

Project: neubot
Source File: unix.py
View license
def __main():
    ''' Neubot auto-updater process '''

    # Process command line options
    logopt = syslog.LOG_PID
    daemonize = True

    try:
        options, arguments = getopt.getopt(sys.argv[1:], 'adv')
    except getopt.error:
        sys.exit('Usage: neubot/updater/unix.py [-adv]')

    if arguments:
        sys.exit('Usage: neubot/updater/unix.py [-adv]')

    check_for_updates = 0  # By default we don't check for updates
    for tpl in options:
        if tpl[0] == '-a':
            check_for_updates = 1
        elif tpl[0] == '-d':
            daemonize = False
        elif tpl[0] == '-v':
            logopt |= syslog.LOG_PERROR|syslog.LOG_NDELAY

    # We must be run as root
    if os.getuid() != 0 and os.geteuid() != 0:
        sys.exit('FATAL: You must be root.')

    # Open the system logger
    syslog.openlog('neubot(updater)', logopt, syslog.LOG_DAEMON)

    # Clear root user environment
    utils_posix.chuser(utils_posix.getpwnam('root'))

    # Daemonize
    if daemonize:
        utils_posix.daemonize('/var/run/neubot.pid')

    #
    # TODO We should install a signal handler that kills
    # properly the child process when requested to exit
    # gracefully.
    #

    firstrun = True
    pid = -1

    signal.signal(signal.SIGUSR1, __sigusr1_handler)

    #
    # Loop forever, catch and just log all exceptions.
    # Spend many time sleeping and wake up just once every
    # few seconds to make sure everything is fine.
    #
    while True:
        if firstrun:
            firstrun = False
        else:
            time.sleep(15)

        # Read configuration files
        CONFIG.update(utils_rc.parse_safe('/etc/neubot/updater'))
        CONFIG.update(utils_rc.parse_safe('/etc/neubot/users'))

        try:

            # If needed start the agent
            if pid == -1:
                syslog.syslog(syslog.LOG_INFO, 'Starting the agent')
                pid = __start_neubot_agent()

            # Check for updates
            now = time.time()
            updates_check_in = 1800 - (now - STATE['lastcheck'])
            if updates_check_in <= 0:
                STATE['lastcheck'] = now

                if check_for_updates:
                    nversion = _download_and_verify_update()
                    if nversion:
                        if pid > 0:
                            __stop_neubot_agent(pid)
                            pid = -1
                        __install_new_version(nversion)
                        __switch_to_new_version()
                        raise RuntimeError('Internal error')

                    #
                    # We have not found an update, while here make
                    # sure that we keep clean our base directory,
                    # remove old files and directories, the tarball
                    # of this version, etc.
                    #
                    else:
                        __clear_base_directory()
                else:
                    syslog.syslog(syslog.LOG_DEBUG, 'Auto-updates are disabled')

            elif check_for_updates:
                syslog.syslog(syslog.LOG_DEBUG,
                  'Auto-updates check in %d sec' % updates_check_in)

            # Monitor the agent
            rpid, status = __waitpid(pid, 0)

            if rpid == pid:
                pid = -1

                # Signaled?
                if os.WIFSIGNALED(status):
                    raise RuntimeError('Agent terminated by signal')

                # For robustness
                if not os.WIFEXITED(status):
                    raise RuntimeError('Internal error in __waitpid()')

                syslog.syslog(syslog.LOG_WARNING,
                  'Child exited with status %d' % os.WEXITSTATUS(status))

        except:
            try:
                why = asyncore.compact_traceback()
                syslog.syslog(syslog.LOG_ERR, 'In main loop: %s' % str(why))
            except:
                pass

Example 27

Project: neubot
Source File: system_posix.py
View license
def get_background_logger():
    ''' Return the background logger '''
    syslog.openlog("neubot", syslog.LOG_PID, syslog.LOG_DAEMON)
    return __logger

Example 28

Project: neubot
Source File: utils_posix.py
View license
    def __init__(self):
        logging.Handler.__init__(self)
        syslog.openlog('neubot', syslog.LOG_PID, syslog.LOG_DAEMON)

Example 29

Project: neubot
Source File: unix.py
View license
def __main():
    ''' Neubot auto-updater process '''

    # Process command line options
    logopt = syslog.LOG_PID
    daemonize = True

    try:
        options, arguments = getopt.getopt(sys.argv[1:], 'adv')
    except getopt.error:
        sys.exit('Usage: neubot/updater/unix.py [-adv]')

    if arguments:
        sys.exit('Usage: neubot/updater/unix.py [-adv]')

    check_for_updates = 0  # By default we don't check for updates
    for tpl in options:
        if tpl[0] == '-a':
            check_for_updates = 1
        elif tpl[0] == '-d':
            daemonize = False
        elif tpl[0] == '-v':
            logopt |= syslog.LOG_PERROR|syslog.LOG_NDELAY

    # We must be run as root
    if os.getuid() != 0 and os.geteuid() != 0:
        sys.exit('FATAL: You must be root.')

    # Open the system logger
    syslog.openlog('neubot(updater)', logopt, syslog.LOG_DAEMON)

    # Clear root user environment
    utils_posix.chuser(utils_posix.getpwnam('root'))

    # Daemonize
    if daemonize:
        utils_posix.daemonize('/var/run/neubot.pid')

    #
    # TODO We should install a signal handler that kills
    # properly the child process when requested to exit
    # gracefully.
    #

    firstrun = True
    pid = -1

    signal.signal(signal.SIGUSR1, __sigusr1_handler)

    #
    # Loop forever, catch and just log all exceptions.
    # Spend many time sleeping and wake up just once every
    # few seconds to make sure everything is fine.
    #
    while True:
        if firstrun:
            firstrun = False
        else:
            time.sleep(15)

        # Read configuration files
        CONFIG.update(utils_rc.parse_safe('/etc/neubot/updater'))
        CONFIG.update(utils_rc.parse_safe('/etc/neubot/users'))

        try:

            # If needed start the agent
            if pid == -1:
                syslog.syslog(syslog.LOG_INFO, 'Starting the agent')
                pid = __start_neubot_agent()

            # Check for updates
            now = time.time()
            updates_check_in = 1800 - (now - STATE['lastcheck'])
            if updates_check_in <= 0:
                STATE['lastcheck'] = now

                if check_for_updates:
                    nversion = _download_and_verify_update()
                    if nversion:
                        if pid > 0:
                            __stop_neubot_agent(pid)
                            pid = -1
                        __install_new_version(nversion)
                        __switch_to_new_version()
                        raise RuntimeError('Internal error')

                    #
                    # We have not found an update, while here make
                    # sure that we keep clean our base directory,
                    # remove old files and directories, the tarball
                    # of this version, etc.
                    #
                    else:
                        __clear_base_directory()
                else:
                    syslog.syslog(syslog.LOG_DEBUG, 'Auto-updates are disabled')

            elif check_for_updates:
                syslog.syslog(syslog.LOG_DEBUG,
                  'Auto-updates check in %d sec' % updates_check_in)

            # Monitor the agent
            rpid, status = __waitpid(pid, 0)

            if rpid == pid:
                pid = -1

                # Signaled?
                if os.WIFSIGNALED(status):
                    raise RuntimeError('Agent terminated by signal')

                # For robustness
                if not os.WIFEXITED(status):
                    raise RuntimeError('Internal error in __waitpid()')

                syslog.syslog(syslog.LOG_WARNING,
                  'Child exited with status %d' % os.WEXITSTATUS(status))

        except:
            try:
                why = asyncore.compact_traceback()
                syslog.syslog(syslog.LOG_ERR, 'In main loop: %s' % str(why))
            except:
                pass

Example 30

Project: neubot
Source File: utils_posix.py
View license
    def __init__(self):
        logging.Handler.__init__(self)
        syslog.openlog('neubot', syslog.LOG_PID, syslog.LOG_DAEMON)