def __init__(self, filename=None, *args, **kwargs): ZMQHandler.__init__( self, None, destination=get_log_path(icswLogHandleTypes.log_py), ) self.__lens = {"name": 1, "threadName": 1, "lineno": 1}
def main(): zmq_context = zmq.Context() log_template = logging_tools.get_logger( "syslog_scan", get_log_path(icswLogHandleTypes.log_py), context=zmq_context ) send_sock = None log_template.log(logging_tools.LOG_LEVEL_OK, "starting syslog_scan") while True: line = sys.stdin.readline().strip() if not line: break try: _timestamp, host, msg = line.split(None, 2) except: log_template.log( logging_tools.LOG_LEVEL_ERROR, "error parsing line {}: {}".format(line, process_tools.get_except_info()) ) else: log_template.log("got line from {}: {}".format(host, msg)) if not send_sock: send_sock = open_socket(zmq_context) send_sock.send_unicode(msg) if send_sock: send_sock.close() log_template.log(logging_tools.LOG_LEVEL_OK, "received empty line, exiting") log_template.close() zmq_context.term()
def __init__(self): self.__log_template = logging_tools.get_logger( "jsv_{:d}".format(os.getuid()), get_log_path(icswLogHandleTypes.log_py), ) self.__state = "initialized" self.env = {} self.param = {}
def process_init(self): self.__log_template = logging_tools.get_logger( self.__options.log_name, get_log_path(icswLogHandleTypes(self.__options.handle)), context=self.zmq_context ) self.__log_template.log_command("set_max_line_length {:d}".format(256)) self.__log_str = self.__options.mult * (" ".join(self.__options.args)) self.log("log_str has {}".format(logging_tools.get_plural("byte", len(self.__log_str)))) self.register_func("start_logging", self._start_logging)
def __init__(self, sock_name="/var/lib/logging-server/py_err_py_zmq", **kwargs): self.__buffered = kwargs.get("buffered", False) # late init of context and socket to reduce threads self.__zmq_context = kwargs.get("zmq_context", None) self.__zmq_sock = None self.__buffer = "" if isinstance(sock_name, icswLogHandleTypes): sock_name = get_log_path(sock_name) self.__sock_name = self.zmq_socket_name(sock_name, check_ipc_prefix=True) if kwargs.get("register_atexit", True): atexit.register(self.close)
def get_logger(name, options, **kwargs): log_type = options.logger log_all = options.logall if log_type == "stdout": if log_all or kwargs.get("all", False): return _get_logger(True) else: return _get_logger(False) else: return logging_tools.get_logger( "icsw_{}".format(name), get_log_path(icswLogHandleTypes.log_py), ).log
def build_main(opt_ns): global_config.add_config_entries( [ ("VERBOSE", configfile.BoolConfigVar(opt_ns.verbose)), ("IGNORE_ERRORS", configfile.BoolConfigVar(opt_ns.ignore_errors)), ("LOG_DESTINATION", configfile.StringConfigVar(get_log_path(icswLogHandleTypes.log_py))), ("LOG_NAME", configfile.StringConfigVar("build_image")), ("BUILDERS", configfile.IntegerConfigVar(4)), ("OVERRIDE", configfile.BoolConfigVar(opt_ns.override)), ("CLEAR_LOCK", configfile.BoolConfigVar(opt_ns.clear_lock)), ("SET_LOCK", configfile.BoolConfigVar(opt_ns.set_lock)), ("SKIPCLEANUP", configfile.BoolConfigVar(opt_ns.skip_cleanup)), ("CHECK_SIZE", configfile.BoolConfigVar(True)), ("IMAGE_NAME", configfile.StringConfigVar(opt_ns.image)), ] ) return ServerProcess().loop()
def __init__(self, options): self.__options = options self.__log_template, self.__log_cache = (None, []) threading_tools.icswProcessPool.__init__(self, self.__options.log_name) self.__log_template = logging_tools.get_logger( options.log_name, get_log_path(icswLogHandleTypes(options.handle)), context=self.zmq_context ) self.__log_template.log_command("set_max_line_length {:d}".format(256)) self.register_func("stop_logging", self._stop_logging) self.__process_names = [] # init processes for t_num in range(self.__options.processes): cur_name = "process_{:d}".format(t_num + 1) self.add_process(MyLogProcess(cur_name, self.__options, self.__log_template), start=True) self.__process_names.append(cur_name) self.__processes_running = len(self.__process_names) self.__bytes_total = 0 [self.send_to_process(t_name, "start_logging") for t_name in self.__process_names]
def main(): zmq_context = zmq.Context() logger = logging_tools.get_logger("openvpn_tls_check", get_log_path(icswLogHandleTypes.log_py), context=zmq_context) # for key in sorted(os.environ): # logger.info("%s: %s" % (key, str(os.environ[key]))) ret_code = 1 if len(sys.argv) == 3: if sys.argv[1] == "0": if "config" in os.environ: match_name = "{}.tls_match".format(os.environ["config"][:-5]) if os.path.isfile(match_name): logger.info( "checking X_509_name '{}' against match_list '{}', remote_ip is {}" .format(sys.argv[2], match_name, os.environ["untrusted_ip"])) # get CN (common name) parts = [ part.strip().split("=", 1) for part in sum([ _part.split(",") for _part in sys.argv[2].split("/") ], []) if part.strip().count("=") ] value_dict = dict([(key, value) for key, value in parts]) if "CN" in value_dict: cn = value_dict["CN"] try: match_dict = dict([ parse_line(line) for line in open( match_name, "r").read().split("\n") if line.strip() and not line.strip().startswith("#") ]) except: logger.error( "cannot read match-file {}: {}".format( match_name, process_tools.get_except_info())) else: if cn in match_dict: logger.info("CN {} in match_list".format(cn)) a_struct = match_dict[cn] if a_struct: if a_struct.is_allowed(logger): ret_code = 0 else: ret_code = 0 elif "*" in match_dict: logger.warning( "CN {} accepted by wildcard *".format(cn)) ret_code = 0 else: logger.error( "CN {} not in match_list {}".format( cn, match_name)) else: logger.critical( "No CN found in X_509_name '{}'".format( sys.argv[2])) else: logger.critical( "no match_name {} found".format(match_name)) else: logger.critical("No config environment variable found") else: ret_code = 0 else: logger.critical("Need 3 arguments, {:d} found".format(len(sys.argv))) logger.close() zmq_context.term() return ret_code
def main(): # change IO-descriptors zmq_context = zmq.Context() log_template = logging_tools.get_logger( "loadsensor", get_log_path(icswLogHandleTypes.log_py), context=zmq_context, ) base_dir = "/etc/sysconfig/licenses" my_pid = os.getpid() sge_dict = sge_license_tools.get_sge_environment() log_template.info("starting for pid {:d}, base_dir is {}".format( my_pid, base_dir)) log_template.info(sge_license_tools.get_sge_log_line(sge_dict)) _act_site_file = sge_license_tools.LicenseTextFile( os.path.join(base_dir, sge_license_tools.ACT_SITE_NAME), ) act_site = _act_site_file.lines if not act_site: log_template.error("Actual site not defined, exiting...") sys.exit(1) act_site = act_site[0] act_conf = sge_license_tools.LicenseTextFile( sge_license_tools.get_site_config_file_name(base_dir, act_site), ).dict log_template.info("read config for actual site '{}'".format(act_site)) log_template.info("{} in config:".format( logging_tools.get_plural("key", len(list(act_conf.keys()))))) for key, value in act_conf.items(): log_template.info(" - {:<20s} : {}".format(key, value)) call_num = 0 io_in_fd = sys.stdin.fileno() io_out_fd = sys.stdout.fileno() log_template.info( "starting up, input handle is {:d}, output handle is {:d}".format( io_in_fd, io_out_fd)) actual_licenses, lic_read_time = ([], time.time()) # read node_grouping file # ng_dict = sge_license_tools.read_ng_file(log_template) # license_check_dict lc_object = None # vector socket try: while True: in_lines = raw_read(io_in_fd) call_num += 1 if in_lines == "quit": log_template.warning("call #{:d}, received '{}'".format( call_num, in_lines)) break else: log_template.info( "starting reporting load values (call #{:d})".format( call_num)) start_time = time.time() site_lic_file_name = sge_license_tools.get_site_license_file_name( base_dir, act_site) if os.path.isfile(site_lic_file_name): file_time = os.stat(site_lic_file_name)[stat.ST_MTIME] if not actual_licenses or file_time > lic_read_time: log_template.info( "reading license_file for site {}".format( act_site)) actual_licenses = sge_license_tools.parse_license_lines( sge_license_tools.LicenseTextFile( sge_license_tools.get_site_license_file_name( base_dir, act_site), ignore_missing=True, strip_empty=False, strip_hash=False, ).lines, act_site) lic_read_time = file_time if not sge_license_tools.handle_license_policy(base_dir): cur_used = { _key: _value.used for _key, _value in actual_licenses.items() } srv_result = parse_actual_license_usage( log_template, actual_licenses, act_conf, lc_object) sge_license_tools.update_usage(actual_licenses, srv_result) # [cur_lic.handle_node_grouping() for cur_lic in actual_licenses.itervalues()] for log_line, log_level in sge_license_tools.handle_complex_licenses( actual_licenses): log_template.log(log_line, log_level) sge_license_tools.calculate_usage(actual_licenses) configured_licenses = [ _key for _key, _value in actual_licenses.items() if _value.is_used ] sge_lines, rep_dict = build_sge_report_lines( log_template, configured_licenses, actual_licenses, cur_used) else: log_template.log( "licenses are controlled via rms-server, reporting nothing to SGE", logging_tools.LOG_LEVEL_WARN) sge_lines, rep_dict = ([], None) # report to SGE print("\n".join(sge_lines)) end_time = time.time() if rep_dict: log_template.info( "{} defined, {:d} configured, {:d} in use{}, ({:d} simple, {:d} complex), took {}" .format( logging_tools.get_plural( "license", len(list(actual_licenses.keys()))), len(configured_licenses), len(rep_dict["lics_in_use"]), rep_dict["lics_in_use"] and " ({})".format( ", ".join(sorted(rep_dict["lics_in_use"]))) or "", rep_dict["simple_lics"], rep_dict["complex_lics"], logging_tools.get_diff_time_str(end_time - start_time))) else: log_template.warning( "site_file for site {} not readable (base_dir is {})". format(act_site, base_dir)) except KeyboardInterrupt: log_template.warning( "proc {:d}: got KeyboardInterrupt, exiting ...".format(my_pid)) except term_error: log_template.warning( "proc {:d}: got term-signal, exiting ...".format(my_pid)) except stop_error: log_template.warning( "proc {:d}: got stop-signal, exiting ...".format(my_pid)) except int_error: log_template.warning( "proc {:d}: got int-signal, exiting ...".format(my_pid)) log_template.close() zmq_context.term() sys.exit(0)
def __init__(self, filename=None, *args, **kwargs): ZMQHandler.__init__( self, None, destination=get_log_path(icswLogHandleTypes.log_py), )