Skip to content

Commit

Permalink
Merge d3d23d9 into b06245c
Browse files Browse the repository at this point in the history
  • Loading branch information
gardart committed May 27, 2020
2 parents b06245c + d3d23d9 commit 9038571
Show file tree
Hide file tree
Showing 37 changed files with 356 additions and 317 deletions.
14 changes: 8 additions & 6 deletions .travis.yml
@@ -1,6 +1,7 @@
language: python
python:
- '2.7'
- '3.7'
env:
matrix:
- DJANGO_VERSION="Django<1.9"
Expand Down Expand Up @@ -110,14 +111,14 @@ install:
- sudo tar -xzvf pnp4nagios-0.6.24.tar.gz
- cd pnp4nagios-0.6.24
- sudo ./configure
--prefix=${NAGIOS_HOME}
--with-nagios-user=${NAGIOS_USER}
--with-nagios-group=${NAGIOS_GROUP}
--prefix=${NAGIOS_HOME}
--with-nagios-user=${NAGIOS_USER}
--with-nagios-group=${NAGIOS_GROUP}
--sysconfdir=${NAGIOS_HOME}/etc/pnp
--exec-prefix=${NAGIOS_HOME}
--datarootdir=${NAGIOS_HOME}/share/pnp
--datarootdir=${NAGIOS_HOME}/share/pnp
--with-rrdtool=/usr/bin/rrdtool
--sysconfdir=${NAGIOS_HOME}/etc/pnp
--sysconfdir=${NAGIOS_HOME}/etc/pnp
--with-perfdata-dir=${NAGIOS_HOME}/share/perfdata
--with-perfdata-logfile=${NAGIOS_HOME}/var/perfdata.log
--with-perfdata-spool-dir=${NAGIOS_HOME}/var/spool/perfdata
Expand Down Expand Up @@ -171,6 +172,7 @@ install:
- export APACHE_LOG_DIR=/var/log/apache2

- sudo usermod -G www-data nagios
- pip install future
- pip install $DJANGO_VERSION
- pip install mock
- pip install simplejson
Expand Down Expand Up @@ -226,7 +228,7 @@ install:
- cp -r /usr/share/okconfig/templates/* ${NAGIOS_HOME}/etc/okconfig/templates/
- cp -r /usr/share/okconfig/examples/* ${NAGIOS_HOME}/etc/okconfig/examples/
- pynag config --append cfg_dir=${NAGIOS_HOME}/etc/okconfig
- ls -l ${NAGIOS_HOME}/etc/okconfig
- ls -l ${NAGIOS_HOME}/etc/okconfig

# Configure Adagios
- pynag config --append "broker_module=/usr/local/nagios/lib/mk-livestatus/livestatus.o /usr/local/nagios/var/rw/live"
Expand Down
2 changes: 1 addition & 1 deletion adagios/__init__.py
Expand Up @@ -63,7 +63,7 @@ def add_plugin(name="myplugin", modulepath=None):
# will successfully start up if any of the plugins have errors
try:
from adagios import settings
for k,v in settings.plugins.items():
for k,v in list(settings.plugins.items()):
try:
add_plugin(k,v)
except Exception:
Expand Down
4 changes: 3 additions & 1 deletion adagios/auth.py
Expand Up @@ -19,6 +19,8 @@
"""

from builtins import str
from builtins import object
import adagios.status.utils
import adagios.views

Expand Down Expand Up @@ -186,5 +188,5 @@ def process_view(self, request, view_func, view_args, view_kwargs):
try:
path = module_name + '.' + function_name
check_access_to_path(request, path)
except adagios.exceptions.AccessDenied, e:
except adagios.exceptions.AccessDenied as e:
return adagios.views.http_403(request, exception=e)
56 changes: 28 additions & 28 deletions adagios/bi/__init__.py
@@ -1,3 +1,4 @@
from __future__ import division
# Adagios is a web based Nagios configuration interface
#
# Copyright (C) 2014, Pall Sigurdsson <palli@opensource.is>
Expand All @@ -15,6 +16,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from builtins import str
from builtins import object
from past.utils import old_div
from pynag.Utils import PynagError, defaultdict

__author__ = 'palli'
Expand Down Expand Up @@ -122,7 +126,7 @@ def get_status(self):
self.errors.append(
_("We have not implemented how to use status method %s") % str(self.status_method))
return 3
except Exception, e:
except Exception as e:
self.errors.append(e)
return 3

Expand All @@ -137,14 +141,14 @@ def get_state_summary(self):

def get_all_states(self):
""" Returns a list of all subprocess states """
return map(lambda x: x.get_status(), self.get_processes())
return [x.get_status() for x in self.get_processes()]

def get_worst_state(self):
""" Returns the worst state of any sub items
"""
try:
return int(max(self.get_all_states()))
except Exception, e:
except Exception as e:
self.errors.append(e)
return 3

Expand All @@ -153,7 +157,7 @@ def get_best_state(self):
"""
try:
return int(min(self.get_all_states()))
except Exception, e:
except Exception as e:
self.errors.append(e)
return 3

Expand Down Expand Up @@ -191,7 +195,7 @@ def run_business_rules(self):
states = tags[tag]

# Filter out states ok
states = filter(lambda x: x > 0, states)
states = [x for x in states if x > 0]
if not states: # Nothing more to do
continue
if len(states) >= num_problems:
Expand Down Expand Up @@ -255,7 +259,7 @@ def resolve_macrostring(self, string):
all_macros = self.resolve_all_macros()
try:
return string.format(**all_macros)
except KeyError, e:
except KeyError as e:
raise PynagError(_("Invalid macro in string. %s") % str(e))

def resolve_macro(self, macroname, default='raise exception'):
Expand Down Expand Up @@ -288,23 +292,23 @@ def resolve_macro(self, macroname, default='raise exception'):
elif macroname == 'percent_state_0':
if len(self.get_all_states()) == 0:
return 0
return 100.0 * state_summary[0] / sum(state_summary)
return old_div(100.0 * state_summary[0], sum(state_summary))
elif macroname == 'percent_state_1':
if len(self.get_all_states()) == 0:
return 0
return 100.0 * state_summary[1] / sum(state_summary)
return old_div(100.0 * state_summary[1], sum(state_summary))
elif macroname == 'percent_state_2':
if len(self.get_all_states()) == 0:
return 0
return 100.0 * state_summary[2] / sum(state_summary)
return old_div(100.0 * state_summary[2], sum(state_summary))
elif macroname == 'percent_state_3':
if len(self.get_all_states()) == 0:
return 0
return 100.0 * state_summary[3] / sum(state_summary)
return old_div(100.0 * state_summary[3], sum(state_summary))
elif macroname == 'percent_problems':
if len(self.get_all_states()) == 0:
return 0
return 100.0 * sum(state_summary[1:]) / sum(state_summary)
return old_div(100.0 * sum(state_summary[1:]), sum(state_summary))
elif macroname == 'current_state':
return self.get_status()
elif macroname == 'friendly_state':
Expand Down Expand Up @@ -372,8 +376,7 @@ def remove_pnp_graph(self, host_name, service_description, metric_name):
data['metric_name'] = metric_name
if not self.graphs:
return
self.graphs = filter(
lambda x: frozenset(x) != frozenset(data), self.graphs)
self.graphs = [x for x in self.graphs if frozenset(x) != frozenset(data)]

def get_pnp_last_value(self, host_name, service_description, metric_name):
""" Looks up current nagios perfdata via mk-livestatus and returns the last value for a specific metric (str)
Expand Down Expand Up @@ -572,7 +575,7 @@ def get_status(self):
if service_status == 3:
return 2
return service_status
except Exception, e:
except Exception as e:
self.errors.append(e)
return 3

Expand All @@ -583,11 +586,8 @@ def get_processes(self):
else:
services = self._livestatus.get_services(
'Filter: host_groups >= %s' % self.name)
livestatus_objects = map(
lambda x: [x.get('host_name') + '/' + x.get(
'description'), x.get('state')],
services
)
livestatus_objects = [[x.get('host_name') + '/' + x.get(
'description'), x.get('state')] for x in services]
for i in livestatus_objects:
process = BusinessProcess(i[0])
process.get_status = lambda: i[1]
Expand Down Expand Up @@ -667,7 +667,7 @@ def get_status(self):
try:
self.load()
return self._service.get('state', 3)
except Exception, e:
except Exception as e:
self.errors.append(e)
return 3

Expand All @@ -687,7 +687,7 @@ def load(self):
def get_status(self):
try:
self.load()
except Exception, e:
except Exception as e:
self.errors.append(e)
return 3
method = self.status_method
Expand Down Expand Up @@ -753,7 +753,7 @@ def create_host(self):
self.host_not_found = True
self.errors.append(_("Host not found: ") % self.name)
all_hosts = pynag.Model.Host.objects.all
all_hosts = map(lambda x: x.host_name, all_hosts)
all_hosts = [x.host_name for x in all_hosts]
if self.name not in all_hosts:
host = pynag.Model.Host(use="generic-domain", host_name=self.name, address=self.name)
host.action_url = "http://%s" % self.name
Expand Down Expand Up @@ -819,7 +819,7 @@ def get_all_json(filename=None):
raw_data = None
try:
raw_data = open(filename, 'r').read()
except IOError, e:
except IOError as e:
if e.errno == 2: # File does not exist
return []
if not raw_data:
Expand All @@ -834,7 +834,7 @@ def get_all_processes(filename=None):
result = []
try:
json_data = get_all_json(filename=filename)
except IOError, e:
except IOError as e:
if e.errno == 2:
json_data = []
else:
Expand All @@ -848,7 +848,7 @@ def get_all_processes(filename=None):
def get_all_process_names(filename=None):
""" Return a list of all process names out there
"""
return map(lambda x: x.name, get_all_processes(filename=filename))
return [x.name for x in get_all_processes(filename=filename)]


def get_business_process(process_name, process_type=None, **kwargs):
Expand All @@ -862,13 +862,13 @@ def get_business_process(process_name, process_type=None, **kwargs):
my_business_process = BPClass(process_name)
try:
my_business_process.load()
except Exception, e:
except Exception as e:
my_business_process.errors.append(e)
my_business_process.data.update(kwargs)
return my_business_process


class PNP4NagiosGraph:
class PNP4NagiosGraph(object):

""" Represents one single PNP 4 nagios graph
"""
Expand All @@ -885,5 +885,5 @@ def get_image_urls(self):
'json', host=self.host_name, srv=self.service_description)
graphs = json.loads(json_str)
# only use graphs with same label
graphs = filter(lambda x: x['ds_name'] == self.label, graphs)
graphs = [x for x in graphs if x['ds_name'] == self.label]
return graphs
5 changes: 2 additions & 3 deletions adagios/bi/forms.py
Expand Up @@ -41,8 +41,7 @@ def save(self):
self.bp.remove_process(process_name, process_type)
self.bp.save()

status_method_choices = map(
lambda x: (x, x), adagios.bi.BusinessProcess.status_calculation_methods)
status_method_choices = [(x, x) for x in adagios.bi.BusinessProcess.status_calculation_methods]


class BusinessProcessForm(forms.Form):
Expand Down Expand Up @@ -121,7 +120,7 @@ def add_process(self):
self.bp.save()

choices = 'businessprocess', 'hostgroup', 'servicegroup', 'service', 'host'
process_type_choices = map(lambda x: (x, x), choices)
process_type_choices = [(x, x) for x in choices]


class AddSubProcess(forms.Form):
Expand Down
2 changes: 1 addition & 1 deletion adagios/bi/tests.py
Expand Up @@ -157,7 +157,7 @@ def loadPage(self, url):
c = Client()
response = c.get(url)
self.assertEqual(response.status_code, 200, _("Expected status code 200 for page %s") % url)
except Exception, e:
except Exception as e:
self.assertEqual(True, "Unhandled exception while loading %s: %s" % (url, e))

def test_delete(self):
Expand Down

0 comments on commit 9038571

Please sign in to comment.