def livestatus(request): """ Returns a new pynag.Parsers.mk_livestatus() object with authauser automatically set from request.META['remoteuser'] """ if request is None: authuser = None elif adagios.settings.enable_authorization and not adagios.auth.has_role(request, 'administrators') and not adagios.auth.has_role(request, 'operators'): authuser = request.META.get('REMOTE_USER', None) else: authuser = None backends = get_all_backends() # we remove the disabled backends if backends is not None: try: user = userdata.User(request) if user.disabled_backends is not None: backends = filter(lambda x: x not in user.disabled_backends, backends) clear_notification("userdata problem") except Exception as e: message = "%s: %s" % (type(e), str(e)) add_notification(level="warning", notification_id="userdata problem", message=message) livestatus = pynag.Parsers.MultiSite( nagios_cfg_file=adagios.settings.nagios_config, livestatus_socket_path=adagios.settings.livestatus_path, authuser=authuser) for i in backends: livestatus.add_backend(path=i, name=i) return livestatus
def check_destination_directory(request): """ Check that adagios has a place to store new objects """ dest = settings.destination_directory dest_dir_was_found = False # If there are problems with finding nagios.cfg, we don't # need to display any errors here regarding destination_directories try: Model.config.parse_maincfg() except Exception: return {} for k, v in Model.config.maincfg_values: if k != 'cfg_dir': continue if os.path.normpath(v) == os.path.normpath(dest): dest_dir_was_found = True if not dest_dir_was_found: add_notification(level="warning", notification_id="dest_dir", message=_("Destination for new objects (%s) is not defined in nagios.cfg") % dest) elif not os.path.isdir(dest): add_notification(level="warning", notification_id="dest_dir", message=_("Destination directory for new objects (%s) is not found. Please create it.") % dest) else: clear_notification(notification_id="dest_dir") return {}
def livestatus(request): """ Returns a new pynag.Parsers.mk_livestatus() object with authauser automatically set from request.META['remoteuser'] """ if request is None: authuser = None elif adagios.settings.enable_authorization and not adagios.auth.has_role(request, 'administrators') and not adagios.auth.has_role(request, 'operators'): authuser = request.META.get('REMOTE_USER', None) else: authuser = None backends = get_all_backends() # we remove the disabled backends if backends is not None: try: user = userdata.User(request) if user.disabled_backends is not None: backends = [x for x in backends if x not in user.disabled_backends] clear_notification("userdata problem") except Exception as e: message = "%s: %s" % (type(e), str(e)) add_notification(level="warning", notification_id="userdata problem", message=message) livestatus = pynag.Parsers.MultiSite( nagios_cfg_file=adagios.settings.nagios_config, livestatus_socket_path=adagios.settings.livestatus_path, authuser=authuser) for i in backends: livestatus.add_backend(path=i, name=i) return livestatus
def check_destination_directory(request): """ Check that adagios has a place to store new objects """ dest = settings.destination_directory dest_dir_was_found = False for k, v in Model.config.maincfg_values: if k != 'cfg_dir': continue if os.path.normpath(v) == os.path.normpath(dest): dest_dir_was_found = True if not dest_dir_was_found: add_notification( level="warning", notification_id="dest_dir", message= "Destination for new objects (%s) is not defined in nagios.cfg" % dest) elif not os.path.isdir(dest): add_notification( level="warning", notification_id="dest_dir", message= "Destination directory for new objects (%s) is not found. Please create it." % dest) else: clear_notification(notification_id="dest_dir") return {}
def check_git(request): """ Notify user if there is uncommited data in git repository """ nagiosdir = os.path.dirname(pynag.Model.config.cfg_file) if settings.enable_githandler == True: try: git = pynag.Model.EventHandlers.GitEventHandler( nagiosdir, 'adagios', 'adagios') uncommited_files = git.get_uncommited_files() if len(uncommited_files) > 0: add_notification(level="warning", notification_id="uncommited", message="There are %s uncommited files in %s" % (len(uncommited_files), nagiosdir)) else: clear_notification(notification_id="uncommited") clear_notification(notification_id="git_missing") except pynag.Model.EventHandlers.EventHandlerError, e: if e.errorcode == 128: add_notification( level="warning", notification_id="git_missing", message="Git Handler is enabled but there is no git repository in %s. Please init a new git repository." % nagiosdir) # if okconfig is installed, make sure okconfig is notified of git # settings try: author = request.META.get('REMOTE_USER', 'anonymous') from pynag.Utils import GitRepo import okconfig okconfig.git = GitRepo(directory=os.path.dirname( adagios.settings.nagios_config), auto_init=False, author_name=author) except Exception: pass
def reload_configfile(request): """ Load the configfile from settings.adagios_configfile and put its content in adagios.settings. """ try: clear_notification("configfile") settings.reload_configfile() except Exception, e: add_notification(level="warning", message=str(e), notification_id="configfile")
def reload_configfile(request): """ Load the configfile from settings.adagios_configfile and put its content in adagios.settings. """ try: clear_notification("configfile") settings.reload_configfile() except Exception, e: add_notification( level="warning", message=str(e), notification_id="configfile")
def reload_configfile(request): """ Load the configfile from settings.adagios_configfile and put its content in adagios.settings. """ try: clear_notification("configfile") locals = {} execfile(settings.adagios_configfile,globals(),locals) for k,v in locals.items(): settings.__dict__[k] = v except Exception, e: add_notification(level="warning", message=str(e), notification_id="configfile")
def check_selinux(request): """ Check if selinux is enabled and notify user """ if not settings.warn_if_selinux_is_active == True: return {} try: if open('/sys/fs/selinux/enforce', 'r').readline().strip() == "1": add_notification(level="warning", message='SELinux is enabled, that is not supported, please disable it, see https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/html-single/Security-Enhanced_Linux/index.html#sect-Security-Enhanced_Linux-Enabling_and_Disabling_SELinux-Disabling_SELinux') except Exception: pass return {}
def check_selinux(request): """ Check if selinux is enabled and notify user """ notification_id = "selinux_active" if settings.warn_if_selinux_is_active: try: if open('/sys/fs/selinux/enforce', 'r').readline().strip() == "1": add_notification( level="warning", message=_('SELinux is enabled, which is likely to give your monitoring engine problems., see <a href="https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/html-single/Security-Enhanced_Linux/index.html#sect-Security-Enhanced_Linux-Enabling_and_Disabling_SELinux-Disabling_SELinux">here</a> for information on how to disable it.'), notification_id=notification_id, ) except Exception: pass else: clear_notification(notification_id) return {}
def check_destination_directory(request): """ Check that adagios has a place to store new objects """ dest = settings.destination_directory dest_dir_was_found = False for k,v in Model.config.maincfg_values: if k != 'cfg_dir': continue if os.path.normpath(v) == os.path.normpath(dest): dest_dir_was_found=True if not dest_dir_was_found: add_notification(level="warning",notification_id="dest_dir", message="Destination for new objects (%s) is not defined in nagios.cfg" %dest) elif not os.path.isdir(dest): add_notification(level="warning", notification_id="dest_dir", message="Destination directory for new objects (%s) is not found. Please create it." %dest) else: clear_notification(notification_id="dest_dir") return {}
def check_git(request): """ Notify user if there is uncommited data in git repository """ nagiosdir = os.path.dirname(pynag.Model.config.cfg_file) if settings.enable_githandler == True: try: git = pynag.Model.EventHandlers.GitEventHandler( nagiosdir, 'adagios', 'adagios') uncommited_files = git.get_uncommited_files() if len(uncommited_files) > 0: add_notification( level="warning", notification_id="uncommited", message="There are %s uncommited files in %s" % (len(uncommited_files), nagiosdir)) else: clear_notification(notification_id="uncommited") clear_notification(notification_id="git_missing") except pynag.Model.EventHandlers.EventHandlerError, e: if e.errorcode == 128: add_notification( level="warning", notification_id="git_missing", message= "Git Handler is enabled but there is no git repository in %s. Please init a new git repository." % nagiosdir) # if okconfig is installed, make sure okconfig is notified of git # settings try: author = request.META.get('REMOTE_USER', 'anonymous') from pynag.Utils import GitRepo import okconfig okconfig.git = GitRepo(directory=os.path.dirname( adagios.settings.nagios_config), auto_init=False, author_name=author) except Exception: pass