本文整理汇总了Python中syslog.closelog函数的典型用法代码示例。如果您正苦于以下问题:Python closelog函数的具体用法?Python closelog怎么用?Python closelog使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了closelog函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
parser = OptionParser()
parser.add_option('-W', '--warning', action='store', dest='warning', default=100, type='int', help='The warning threshold we want to set')
parser.add_option('-C', '--critical', action='store', dest='critical', default=200, type='int', help='The critical threshold we want to set')
(options, args) = parser.parse_args()
start = time.time()
# syslog check start
syslog.openlog( 'check_syslog' )
syslog.syslog( syslog.LOG_DEBUG, 'Nagion syslog check' )
syslog.closelog()
# syslog check stop
stop = time.time()
result = int((stop - start) * 1000)
if(result < options.warning):
print "OK - %d ms" % result
return 0
if(result < options.critical):
print "WARNING - %d ms" % result
return 1
else:
print "CRITICAL - %d ms" % result
return 2
示例2: syslog
def syslog(message, ident = "", priority = "info", facility = "syslog", options = []):
"""
Send a string to syslog and return that same string.
"""
priority = { "emerg":SYSLOG.LOG_EMERG, "alert":SYSLOG.LOG_ALERT,
"crit":SYSLOG.LOG_CRIT, "err":SYSLOG.LOG_ERR,
"warning":SYSLOG.LOG_WARNING, "notice":SYSLOG.LOG_NOTICE,
"info":SYSLOG.LOG_INFO, "debug":SYSLOG.LOG_DEBUG }.get(str(priority).lower(),0)
facility = { "kern":SYSLOG.LOG_KERN, "user":SYSLOG.LOG_USER,
"mail":SYSLOG.LOG_MAIL, "daemon":SYSLOG.LOG_DAEMON,
"auth":SYSLOG.LOG_AUTH, "lpr":SYSLOG.LOG_LPR,
"news":SYSLOG.LOG_NEWS, "uucp":SYSLOG.LOG_UUCP,
"cron":SYSLOG.LOG_CRON, "syslog":SYSLOG.LOG_SYSLOG,
"local0":SYSLOG.LOG_LOCAL0, "local1":SYSLOG.LOG_LOCAL1,
"local2":SYSLOG.LOG_LOCAL2, "local3":SYSLOG.LOG_LOCAL3,
"local4":SYSLOG.LOG_LOCAL4, "local5":SYSLOG.LOG_LOCAL5,
"local6":SYSLOG.LOG_LOCAL6, "local7":SYSLOG.LOG_LOCAL7 }.get(str(facility).lower(),0)
option = 0
for opt in options:
option += { "pid":SYSLOG.LOG_PID, "cons":SYSLOG.LOG_CONS, "ndelay":SYSLOG.LOG_NDELAY,
"nowait":SYSLOG.LOG_NOWAIT, "perror":SYSLOG.LOG_PERROR }.get(str(opt).lower(),0)
message = str(message)
ident = str(ident)
if not ident: ident = os.path.basename(sys.argv[0])
SYSLOG.openlog(ident = ident, logoption = option, facility = facility)
add = ""
for line in message.split("\n"):
if line:
SYSLOG.syslog(priority, add + line)
add = " "
SYSLOG.closelog()
return message
示例3: emit
def emit(self, record):
hand = syslog.openlog(facility=self.facility)
msg = self.format(record)
syslog.syslog(
self.priority_names.get(record.levelname.lower(), "debug"),
msg)
syslog.closelog()
示例4: log
def log(txt, force=False):
global log, log_enabled
if not log_enabled and not force:
return
syslog.openlog("skolesys-backup")
syslog.syslog(txt)
syslog.closelog()
示例5: main
def main ():#funcion principal
logs = open("FilesOutput/CompleteTables_Logs_error.txt", 'w')#se abre archivo log
#abrimos syslog para registrar lo que realiza el script...
syslog.openlog("CompleteTables.py", syslog.LOG_USER)
syslog.syslog(syslog.LOG_INFO,"this script has created the next output files CompleteTables_Logs_error.txt")
information_DB = ReadCSV(sys.argv[1])#obtenemos la informacion de la base de datos...
syslog.syslog(syslog.LOG_INFO, "Completando datos en tablas no relacionadas")
#se generan las conexiones
data_connected_import = ConnectDB(information_DB['import'][0], information_DB['import'][1], information_DB['import'][2], information_DB['import'][3])
data_connected_export = ConnectDB(information_DB['export'][0], information_DB['export'][1], information_DB['export'][2], information_DB['export'][3])
#se realiza el mismo proceso para las diferentes tablas...
#insertando elementos tabla tipodispositivo
CompleteProcessInsertion(data_connected_export[1], data_connected_export[0], data_connected_import[1], data_connected_import[0], "tipo_dispositivo", "tipodispositivo", "tipo", "tipodispositivo_id_seq", 1)
#insertando elementos tabla marca
CompleteProcessInsertion(data_connected_export[1], data_connected_export[0], data_connected_import[1], data_connected_import[0], "marca", "marca", "marca", "marca_id_seq", 1)
#insertando elementos tabla tipousuario
CompleteProcessInsertion(data_connected_export[1], data_connected_export[0], data_connected_import[1], data_connected_import[0], "tipo_usuario", "tipousuario", "tipo", "tipousuario_id_seq", 0)
#insertando elementos tabla estadodispositivo and tabla estadousuario
CompleteProcessInsertion(data_connected_export[1], data_connected_export[0], data_connected_import[1], data_connected_import[0], "estado", "estadodispositivo", "descripcion", "estadodispositivo_id_seq", 1)
logs.write("ok")
logs.close()
syslog.closelog()#cerramos syslog
return 0
示例6: error
def error(*args):
msg = make_msg(args)
if sys.stderr.isatty():
logging.error(msg)
syslog.openlog(ident, syslog.LOG_NDELAY, facility)
syslog.syslog(syslog.LOG_ERR, msg)
syslog.closelog()
示例7: log_warning
def log_warning(msg, syslog_identifier, also_print_to_console=False):
syslog.openlog(syslog_identifier)
syslog.syslog(syslog.LOG_WARNING, msg)
syslog.closelog()
if also_print_to_console:
print msg
示例8: log
def log(self, msg=''):
if msg != '':
sys.stdout.write(self.script_path + ': ' + str(msg) + '\n')
syslog.openlog(ident='openvpn ' + self.name + ' ' + self.instance,
logoption=0, facility=syslog.LOG_DAEMON)
syslog.syslog(syslog.LOG_INFO, msg)
syslog.closelog()
示例9: log_warning
def log_warning(msg, also_print_to_console=False):
syslog.openlog(SYSLOG_IDENTIFIER)
syslog.syslog(syslog.LOG_WARNING, msg)
syslog.closelog()
if also_print_to_console:
click.echo(msg)
示例10: main
def main ():
#abrimos syslog para registrar lo que realiza el script...
syslog.openlog("RemoveElementsConflictiv.py", syslog.LOG_USER)
information_DB = ReadCSV(sys.argv[1])#obtenemos la informacion de la base de datos...
# #make connections...
data_connected_import = ConnectDB(information_DB['import'][0], information_DB['import'][1], information_DB['import'][2], information_DB['import'][3])
data_connected_export = ConnectDB(information_DB['export'][0], information_DB['export'][1], information_DB['export'][2], information_DB['export'][3])
print "Removiendo elementos conflictivos y elementos no existentes en csv"
#obtengo la lista de macs...
list_macs = ReadText("FilesOutput/GetMacslist_macs_not_exists.txt")
list_macs_persistentes=RemoveMacsNotInCSV(data_connected_export[1], data_connected_export[0], list_macs)
#eliminamos los datos que presentan problemas de union y que deben almacenar su informacion en un csv...
list_equipos_conflictivos = GetListEquiposConflictivos(data_connected_export[1], data_connected_export[0])#obtenemos la lista de elementos conflictivos...
info_equipos_conflictivos = RecolectaInformacionEquiposConflictivos(data_connected_export[1], list_equipos_conflictivos)
GenerateCSV(info_equipos_conflictivos, data_connected_import[1])
DeleteEquiposConflictivos(data_connected_export[1], data_connected_export[0], list_equipos_conflictivos)
logs = open("FilesOutput/Remove.txt", 'w')
logs.write("ok")
logs.close()
syslog.closelog()#cerramos syslog
return 0
示例11: log
def log(statement, event=False):
statement = str(statement)
# Always print event related messages, even when --quiet is specified
if options.quiet is True and event is False:
return
# Always log to syslog
syslog.openlog("ha-nat")
syslog.syslog(statement)
syslog.closelog()
# Always print to stdout
print statement
# Log to a file if one has been specified
if options.logFile is not None:
if not os.path.exists(os.path.dirname(options.logFile)):
os.makedirs(os.path.dirname(options.logFile))
logFile = open(options.logFile, 'a')
ts = datetime.datetime.now()
isFirst = True
for line in statement.split("\n"):
if isFirst:
logFile.write("%s - %s\n" % (ts, line))
isFirst = False
else:
logFile.write("%s - %s\n" % (ts, line))
logFile.close()
示例12: send_10_log_messages_with_delay
def send_10_log_messages_with_delay():
syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_MAIL)
for ind in range(10):
msg = str(ind + 1) + '. Test Syslog Messages being sent.'
syslog.syslog(syslog.LOG_EMERG, msg)
time.sleep(1)
syslog.closelog()
示例13: send_test_log_message
def send_test_log_message():
syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_KERN)
for ind in range(5):
msg = str(ind + 1) + '. Test Syslog Messages from different nodes.'
syslog.syslog(syslog.LOG_EMERG, msg)
time.sleep(1)
syslog.closelog()
示例14: send_messages_of_all_facility_and_severity
def send_messages_of_all_facility_and_severity():
dict_of_facility = {
'LOG_KERN': 0,
'LOG_USER': 1,
'LOG_MAIL': 2,
'LOG_DAEMON': 3,
'LOG_AUTH': 4,
'LOG_NEWS': 7,
'LOG_UUCP': 8,
'LOG_LOCAL0': 16,
'LOG_CRON': 15,
'LOG_SYSLOG': 5,
'LOG_LOCAL1': 17}
list_of_severity = ['LOG_EMERG', 'LOG_ALERT', 'LOG_CRIT', 'LOG_ERR',
'LOG_WARNING', 'LOG_NOTICE', 'LOG_INFO', 'LOG_DEBUG']
for each_facility in dict_of_facility:
log_facility = dict_of_facility[each_facility]
syslog.openlog(logoption=syslog.LOG_PID, facility=log_facility)
for each_severity in list_of_severity:
log_severity = list_of_severity.index(each_severity)
msg = 'Test Message from ' + each_facility + \
' with severity ' + each_severity + '.'
syslog.syslog(log_severity, msg)
syslog.closelog()
time.sleep(1)
示例15: warning
def warning(*args):
msg = make_msg(args)
if sys.stderr.isatty():
logging.warning(msg)
syslog.openlog(ident, syslog.LOG_NDELAY, facility)
syslog.syslog(syslog.LOG_WARNING, msg)
syslog.closelog()