From: Sven Velt Date: Mon, 21 Feb 2011 19:12:47 +0000 (+0100) Subject: Migrating from "datetime" to "time" X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=69e267becfdb6498254eeb3805c502a30715dc48;p=nagixsc.git Migrating from "datetime" to "time" Windows ActivePython has some problems with "strftime()" from "datetime". All we need is also in "time" - and is much more simple... Signed-off-by: Sven Velt --- diff --git a/nagixsc/__init__.py b/nagixsc/__init__.py index 827a104..036fe7e 100644 --- a/nagixsc/__init__.py +++ b/nagixsc/__init__.py @@ -2,7 +2,6 @@ import BaseHTTPServer import ConfigParser import SocketServer import base64 -import datetime import libxml2 import mimetools import os @@ -13,6 +12,7 @@ import socket import string import subprocess import sys +import time import urllib2 def debug(level, verb, string): @@ -116,7 +116,7 @@ def exec_check(host_name, service_descr, cmdline, cmdprefix='', timeout=None, ti except OSError: pass - check['timestamp'] = datetime.datetime.now().strftime('%s') + check['timestamp'] = str(long(time.time())) return check @@ -211,7 +211,7 @@ def dict2out_passive(checks, xmltimestamp, opt_pipe, opt_verb=0): FORMAT_HOST = '[%s] PROCESS_HOST_CHECK_RESULT;%s;%s;%s' FORMAT_SERVICE = '[%s] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%s;%s' count_services = 0 - now = datetime.datetime.now().strftime('%s') + now = str(long(time.time())) # Prepare if opt_verb <= 2: @@ -252,7 +252,7 @@ def dict2out_checkresult(checks, xmltimestamp, opt_checkresultdir, opt_verb=0): count_failed = 0 list_failed = [] chars = string.letters + string.digits - ctimestamp = datetime.datetime.now().ctime() + ctimestamp = time.ctime() random.seed() for check in checks: @@ -373,7 +373,7 @@ def xml_get_timestamp(xmldoc): def xml_to_dict(xmldoc, verb=0, hostfilter=None, servicefilter=None): checks = [] - now = int(datetime.datetime.now().strftime('%s')) + now = long(time.time()) filetimestamp = reset_future_timestamp(xml_get_timestamp(xmldoc), now) if hostfilter: @@ -449,7 +449,7 @@ def xml_from_dict(checks, encoding='base64'): xmldoc = libxml2.newDoc('1.0') xmlroot = xmldoc.newChild(None, 'nagixsc', None) xmlroot.setProp('version', '1.0') - xmltimestamp = xmlroot.newChild(None, 'timestamp', datetime.datetime.now().strftime('%s')) + xmltimestamp = xmlroot.newChild(None, 'timestamp', str(long(time.time()))) for entry in db: check = entry[1] diff --git a/nagixsc_read_xml.py b/nagixsc_read_xml.py index 53bbf9b..81470ef 100755 --- a/nagixsc_read_xml.py +++ b/nagixsc_read_xml.py @@ -1,10 +1,10 @@ #!/usr/bin/python #import base64 -import datetime import libxml2 import optparse import sys +import time parser = optparse.OptionParser() @@ -34,7 +34,7 @@ from nagixsc import * ############################################################################## -now = int(datetime.datetime.now().strftime('%s')) +now = int(time.time()) # Get URL or file doc = read_xml(options) diff --git a/nagixsc_xml2cfg.py b/nagixsc_xml2cfg.py index 9cbd179..fd79639 100755 --- a/nagixsc_xml2cfg.py +++ b/nagixsc_xml2cfg.py @@ -1,7 +1,6 @@ #!/usr/bin/python #import base64 -import datetime import libxml2 import optparse import socket diff --git a/nagixsc_xml2nagios.py b/nagixsc_xml2nagios.py index 3aee034..e05f613 100755 --- a/nagixsc_xml2nagios.py +++ b/nagixsc_xml2nagios.py @@ -1,11 +1,11 @@ #!/usr/bin/python #import base64 -import datetime import libxml2 import optparse import os import sys +import time NAGIOSCMDs = [ '/usr/local/nagios/var/rw/nagios.cmd', '/var/lib/nagios3/rw/nagios.cmd', ] CHECKRESULTDIRs = [ '/usr/local/nagios/var/spool/checkresults', '/var/lib/nagios3/spool/checkresults', ] @@ -93,7 +93,7 @@ elif options.mode == 'active': doc = read_xml(options) # Now timestamp AFTER getting the XML file -now = int(datetime.datetime.now().strftime('%s')) +now = long(time.time()) # Check XML against DTD