def set_smb_conf(self, config={}, operator="unkown", **kwargs): if not isinstance(config, dict): raise StorLeverError("Parameter type error", 500) if len(config) == 0 and len(kwargs) == 0: return config.update(kwargs) not_allowed_keys = ("share_list", ) config = filter_dict(config, not_allowed_keys, True) if "guest_account" in config and config["guest_account"] is not None: try: user_mgr().get_user_info_by_name(config["guest_account"]) except Exception as e: raise StorLeverError("guest_account does not exist", 400) with self.lock: smb_conf = self._load_conf() for name, value in config.items(): if name == "share_list": continue if name in smb_conf and value is not None: smb_conf[name] = value # check config conflict smb_conf = self.smb_conf_schema.validate(smb_conf) # save new conf self._save_conf(smb_conf) self._sync_to_system_conf(smb_conf) logger.log(logging.INFO, logger.LOG_TYPE_CONFIG, "Samba config is updated by user(%s)" % (operator))
def set_agent_conf(self, config={}, operator="unkown", *args, **kwargs): if not isinstance(config, dict): raise StorLeverError("Parameter type error", 500) if len(config) == 0 and len(kwargs) == 0: return config.update(kwargs) not_allow_keys = ( "active_check_server_list", "passive_check_server_list" ) config = filter_dict(config, not_allow_keys, True) with self.lock: zabbix_agent_conf = self._load_conf() for name, value in config.items(): if name in zabbix_agent_conf and value is not None: zabbix_agent_conf[name] = value # check config conflict zabbix_agent_conf = self.zabbix_agentd_conf_schema.validate(zabbix_agent_conf) # save new conf self._save_conf(zabbix_agent_conf) self._sync_to_system_conf(zabbix_agent_conf) logger.log(logging.INFO, logger.LOG_TYPE_CONFIG, "Zabbix agent config is updated by operator(%s)" % (operator))
def set_basic_conf(self, config={}, operator="unkown", **kwargs): if not isinstance(config, dict): raise StorLeverError("Parameter type error", 500) if len(config) == 0 and len(kwargs) == 0: return config.update(kwargs) not_allowed_keys = ( "community_list", "trapsink_list", "monitor_list" ) config = filter_dict(config, not_allowed_keys, True) with self.lock: snmp_conf = self._load_conf() for name, value in config.items(): if name in snmp_conf and value is not None: snmp_conf[name] = value # check config conflict snmp_conf = self.snmp_conf_schema.validate(snmp_conf) # save new conf self._save_conf(snmp_conf) self._sync_to_system_conf(snmp_conf) logger.log(logging.INFO, logger.LOG_TYPE_CONFIG, "SNMP basic config is updated by operator(%s)" % (operator))
def set_agent_conf(self, config={}, operator="unkown", *args, **kwargs): if not isinstance(config, dict): raise StorLeverError("Parameter type error", 500) if len(config) == 0 and len(kwargs) == 0: return config.update(kwargs) not_allow_keys = ("active_check_server_list", "passive_check_server_list") config = filter_dict(config, not_allow_keys, True) with self.lock: zabbix_agent_conf = self._load_conf() for name, value in config.items(): if name in zabbix_agent_conf and value is not None: zabbix_agent_conf[name] = value # check config conflict zabbix_agent_conf = self.zabbix_agentd_conf_schema.validate( zabbix_agent_conf) # save new conf self._save_conf(zabbix_agent_conf) self._sync_to_system_conf(zabbix_agent_conf) logger.log( logging.INFO, logger.LOG_TYPE_CONFIG, "Zabbix agent config is updated by operator(%s)" % (operator))
def set_monitor_list(self, monitor_list=[], operator="unkown"): monitor_list = Schema([self.smartd_monitor_conf_schema]).validate(monitor_list) for i, monitor_conf in enumerate(monitor_list[:]): monitor_list[i] = filter_dict(monitor_conf, ("dev", "mail_to", "mail_test", "mail_exec", "schedule_regexp")) with self.lock: smartd_conf = self._load_conf() smartd_conf["monitor_list"] = monitor_list # check validation for monitor_conf in smartd_conf["monitor_list"]: if not os.path.exists(monitor_conf["dev"]): raise StorLeverError("Device (%s) not found" % (monitor_conf["dev"]), 404) else: mode = os.stat(monitor_conf["dev"])[ST_MODE] if not S_ISBLK(mode): raise StorLeverError("Device (%s) not block device" % (monitor_conf["dev"]), 400) if monitor_conf["mail_exec"] != "" and not os.path.exists(monitor_conf["mail_exec"]): raise StorLeverError("mail_exec (%s) not found" % (monitor_conf["mail_exec"]), 404) # save new conf self._save_conf(smartd_conf) self._sync_to_system_conf(smartd_conf) logger.log(logging.INFO, logger.LOG_TYPE_CONFIG, "Smartd monitor list is updated by operator(%s)" % (operator))
def get_smb_conf(self): with self.lock: smb_conf = self._load_conf() not_allowed_keys = ("share_list", ) smb_conf = filter_dict(smb_conf, not_allowed_keys, True) return smb_conf
def get_basic_conf(self): with self.lock: snmp_conf = self._load_conf() not_allowed_keys = ("community_list", "trapsink_list", "monitor_list") snmp_conf = filter_dict(snmp_conf, not_allowed_keys, True) return snmp_conf
def get_ftp_conf(self): with self.lock: ftp_conf = self._load_conf() not_allowed_keys = ( "user_list", ) ftp_conf = filter_dict(ftp_conf, not_allowed_keys, True) return ftp_conf
def get_agent_conf(self, *args, **kwargs): with self.lock: zabbix_agent_conf = self._load_conf() not_allow_keys = ("active_check_server_list", "passive_check_server_list") zabbix_agent_conf = filter_dict(zabbix_agent_conf, not_allow_keys, True) return zabbix_agent_conf
def get_monitor_list(self): with self.lock: smartd_conf = self._load_conf() monitor_list = smartd_conf["monitor_list"] for i, monitor_conf in enumerate(monitor_list[:]): monitor_list[i] = filter_dict(monitor_conf, ("dev", "mail_to", "mail_test", "mail_exec", "schedule_regexp")) return monitor_list
def get_agent_conf(self, *args, **kwargs): with self.lock: zabbix_agent_conf = self._load_conf() not_allow_keys = ( "active_check_server_list", "passive_check_server_list" ) zabbix_agent_conf = filter_dict(zabbix_agent_conf, not_allow_keys, True) return zabbix_agent_conf
def get_basic_conf(self): with self.lock: snmp_conf = self._load_conf() not_allowed_keys = ( "community_list", "trapsink_list", "monitor_list" ) snmp_conf = filter_dict(snmp_conf, not_allowed_keys, True) return snmp_conf
def get_tgt_conf(self): with self.lock: tgt_conf = self._load_conf() not_allowed_keys = ("target_list", ) tgt_conf = filter_dict(tgt_conf, not_allowed_keys, True) # hide the password if tgt_conf["incomingdiscoveryuser"] != "": name, sep, password = tgt_conf["incomingdiscoveryuser"].partition( ":") tgt_conf["incomingdiscoveryuser"] = name.strip() + ":" + "*" if tgt_conf["outgoingdiscoveryuser"] != "": name, sep, password = tgt_conf["outgoingdiscoveryuser"].partition( ":") tgt_conf["outgoingdiscoveryuser"] = name.strip() + ":" + "*" return tgt_conf
def get_tgt_conf(self): with self.lock: tgt_conf = self._load_conf() not_allowed_keys = ( "target_list", ) tgt_conf = filter_dict(tgt_conf, not_allowed_keys, True) # hide the password if tgt_conf["incomingdiscoveryuser"] != "": name, sep, password = tgt_conf["incomingdiscoveryuser"].partition(":") tgt_conf["incomingdiscoveryuser"] = name.strip() + ":" + "*" if tgt_conf["outgoingdiscoveryuser"] != "": name, sep, password = tgt_conf["outgoingdiscoveryuser"].partition(":") tgt_conf["outgoingdiscoveryuser"] = name.strip() + ":" + "*" return tgt_conf
def set_ftp_conf(self, config={}, operator="unkown", **kwargs): if not isinstance(config, dict): raise StorLeverError("Parameter type error", 500) if len(config) == 0 and len(kwargs) == 0: return config.update(kwargs) not_allowed_keys = ( "user_list", ) config = filter_dict(config, not_allowed_keys, True) with self.lock: ftp_conf = self._load_conf() for name, value in config.items(): if name in ftp_conf and value is not None: ftp_conf[name] = value # check config conflict ftp_conf = self.ftp_conf_schema.validate(ftp_conf) if ftp_conf["listen"] and ftp_conf["listen6"]: raise StorLeverError("listen and listen6 cannot both be true", 400) if ftp_conf["local_root"] != "" and \ (not os.path.exists(ftp_conf["local_root"])): raise StorLeverError("local_root does not exist", 400) if ftp_conf["anon_root"] != "" and \ (not os.path.exists(ftp_conf["anon_root"])): raise StorLeverError("anon_root does not exist", 400) try: user_mgr().get_user_info_by_name(ftp_conf["anon_username"]) except Exception as e: raise StorLeverError("anon_username does not exist", 400) # save new conf self._save_conf(ftp_conf) self._sync_to_system_conf(ftp_conf) logger.log(logging.INFO, logger.LOG_TYPE_CONFIG, "FTP config is updated by user(%s)" % (operator))
def set_basic_conf(self, config={}, operator="unkown", **kwargs): if not isinstance(config, dict): raise StorLeverError("Parameter type error", 500) if len(config) == 0 and len(kwargs) == 0: return config.update(kwargs) not_allowed_keys = ("community_list", "trapsink_list", "monitor_list") config = filter_dict(config, not_allowed_keys, True) with self.lock: snmp_conf = self._load_conf() for name, value in config.items(): if name in snmp_conf and value is not None: snmp_conf[name] = value # check config conflict snmp_conf = self.snmp_conf_schema.validate(snmp_conf) # save new conf self._save_conf(snmp_conf) self._sync_to_system_conf(snmp_conf) logger.log(logging.INFO, logger.LOG_TYPE_CONFIG, "SNMP basic config is updated by operator(%s)" % (operator))
def set_monitor_list(self, monitor_list=[], operator="unkown"): monitor_list = Schema([self.smartd_monitor_conf_schema ]).validate(monitor_list) for i, monitor_conf in enumerate(monitor_list[:]): monitor_list[i] = filter_dict(monitor_conf, ("dev", "mail_to", "mail_test", "mail_exec", "schedule_regexp")) with self.lock: smartd_conf = self._load_conf() smartd_conf["monitor_list"] = monitor_list # check validation for monitor_conf in smartd_conf["monitor_list"]: if not os.path.exists(monitor_conf["dev"]): raise StorLeverError( "Device (%s) not found" % (monitor_conf["dev"]), 404) else: mode = os.stat(monitor_conf["dev"])[ST_MODE] if not S_ISBLK(mode): raise StorLeverError( "Device (%s) not block device" % (monitor_conf["dev"]), 400) if monitor_conf["mail_exec"] != "" and not os.path.exists( monitor_conf["mail_exec"]): raise StorLeverError( "mail_exec (%s) not found" % (monitor_conf["mail_exec"]), 404) # save new conf self._save_conf(smartd_conf) self._sync_to_system_conf(smartd_conf) logger.log( logging.INFO, logger.LOG_TYPE_CONFIG, "Smartd monitor list is updated by operator(%s)" % (operator))