Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions adagios/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def on_page_load(request):

def update_global_variables():
"""Updates all required global variables."""
pynag.Model.cfg_file = adagios.settings.nagios_config
pynag.Model.config.cfg_file = adagios.settings.nagios_config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact pynag has a global variable for this is not great, and even worse that there are two that go out of sync.

pynag.Model.config looks like an implementation detail of pynag.Model. Maybe best we don't muddle with that too much.

I think what we need here is some logic that whenever pynag.Model.cfg_file is being changed, then pynag.Model.config gets regenerated.

Something like this:

if pynag.Model.cfg_file != adagios.settings.nagios_config:
  pynag.Model.cfg_file = adagios.settings.nagios_config
  Model.ObjectDefinition.objects.reload_cache()

what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we can patch up pynag and turn cfg_file into a property that recreates pynag.Model.config whenever cfg_file is changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, I will try this out



def get_current_time(request):
Expand Down Expand Up @@ -267,7 +267,6 @@ 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:
Expand All @@ -281,7 +280,7 @@ def check_destination_directory(request):
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)
message=_("Destination for new objects (%s) is not defined in %s") % (dest, pynag.Model.config.cfg_file))
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)
Expand Down
4 changes: 2 additions & 2 deletions adagios/objectbrowser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def startup():
"""
from adagios import settings

pynag.Model.cfg_file = settings.nagios_config
pynag.Model.pynag_directory = settings.destination_directory
pynag.Model.config.cfg_file = settings.nagios_config
pynag.Model.config.pynag_directory = settings.destination_directory

# Pre load objects on startup
#pynag.Model.ObjectDefinition.objects.get_all()
Expand Down
2 changes: 1 addition & 1 deletion adagios/objectbrowser/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

from adagios.objectbrowser.forms import PynagAutoCompleteField

pynag.Model.cfg_file = adagios.settings.nagios_config
pynag.Model.config.cfg_file = adagios.settings.nagios_config

try:
from selenium.webdriver.common.by import By
Expand Down