Skip to content

Commit aba1144

Browse files
gardartTravis
andauthored
Python3 support
* Fixed print * Porting to Python3 with Python Future * hotshot profiler module changed to cprofiler * Travis build now includes Python 3 * Future module added to deps * Future module added to deps * fixed unicode str * fixed isinstance unicode * type str fixes * py3 fixes * libmodernize.fixes.fix_basestring * fixed string type issues * keywords must be strings - fixes * fixed cmp in sort * Fixed sorting in dashboard * Fixed top alert producers * test * Fixed hostgroups in status view * fixed link to pnp4nagios tarball * py36 * path fixes for pnp4nagios * fixed okconfig setup * okconfig setup in travis fixed * Fixes for status detail, contacts and testing * Travis changes * added upgrade.sh * Gunicorn support * Gunicorn support * force_script_name * apache reverse proxy support * apache reverse proxy support * apache reverse proxy support * version updated Co-authored-by: Travis <adagios@adagios.org>
1 parent b06245c commit aba1144

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+651
-418
lines changed

.gitignore

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ dist
1010
adagios.conf
1111
*.mo
1212

13-
14-
# Created by https://www.gitignore.io/api/python
15-
# Edit at https://www.gitignore.io/?templates=python
16-
1713
### Python ###
1814
# Byte-compiled / optimized / DLL files
1915
__pycache__/
@@ -134,5 +130,13 @@ dmypy.json
134130
### Python Patch ###
135131
.venv/
136132

137-
# VS Code
138-
.vscode/
133+
### VisualStudioCode ###
134+
.vscode/*
135+
!.vscode/tasks.json
136+
!.vscode/launch.json
137+
*.code-workspace
138+
139+
### VisualStudioCode Patch ###
140+
# Ignore all local history of files
141+
.history
142+
.ionide

.travis.yml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: python
22
python:
3-
- '2.7'
3+
- '3.6'
44
env:
55
matrix:
66
- DJANGO_VERSION="Django<1.9"
@@ -106,18 +106,19 @@ install:
106106
# Install PNP4Nagios
107107
# Build/Install PNP4Nagios
108108
- cd /tmp
109-
- sudo wget http://downloads.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.24.tar.gz
110-
- sudo tar -xzvf pnp4nagios-0.6.24.tar.gz
109+
#- sudo wget http://downloads.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.24.tar.gz
110+
- sudo wget https://github.com/lingej/pnp4nagios/archive/0.6.24.tar.gz
111+
- sudo tar -xzvf 0.6.24.tar.gz
111112
- cd pnp4nagios-0.6.24
112113
- sudo ./configure
113-
--prefix=${NAGIOS_HOME}
114-
--with-nagios-user=${NAGIOS_USER}
115-
--with-nagios-group=${NAGIOS_GROUP}
114+
--prefix=${NAGIOS_HOME}
115+
--with-nagios-user=${NAGIOS_USER}
116+
--with-nagios-group=${NAGIOS_GROUP}
116117
--sysconfdir=${NAGIOS_HOME}/etc/pnp
117118
--exec-prefix=${NAGIOS_HOME}
118-
--datarootdir=${NAGIOS_HOME}/share/pnp
119+
--datarootdir=${NAGIOS_HOME}/share/pnp
119120
--with-rrdtool=/usr/bin/rrdtool
120-
--sysconfdir=${NAGIOS_HOME}/etc/pnp
121+
--sysconfdir=${NAGIOS_HOME}/etc/pnp
121122
--with-perfdata-dir=${NAGIOS_HOME}/share/perfdata
122123
--with-perfdata-logfile=${NAGIOS_HOME}/var/perfdata.log
123124
--with-perfdata-spool-dir=${NAGIOS_HOME}/var/spool/perfdata
@@ -171,6 +172,7 @@ install:
171172
- export APACHE_LOG_DIR=/var/log/apache2
172173

173174
- sudo usermod -G www-data nagios
175+
- pip install future
174176
- pip install $DJANGO_VERSION
175177
- pip install mock
176178
- pip install simplejson
@@ -214,19 +216,22 @@ install:
214216
- sudo setfacl -R -m group:travis:rwx -m d:group:travis:rwx ${NAGIOS_HOME} /etc/okconfig /etc/adagios /var/lib/adagios
215217

216218
# Install OKconfig
217-
- sudo pip install https://github.com/opinkerfi/okconfig/zipball/master
218-
- pip install https://github.com/opinkerfi/okconfig/zipball/master || true
219+
- git clone https://github.com/opinkerfi/okconfig.git ~/build/opinkerfi/okconfig
220+
- cd ~/build/opinkerfi/okconfig/
221+
- python setup.py build
222+
- sudo python setup.py install
223+
- python setup.py install
219224
- sudo touch /etc/okconfig.conf
220225
- sudo chown travis /etc/okconfig.conf
221226
- echo "nagios_config ${NAGIOS_HOME}/etc/nagios.cfg" >> /etc/okconfig.conf
222227
- echo "template_directory ${NAGIOS_HOME}/etc/okconfig/templates" >> /etc/okconfig.conf
223228
- echo "examples_directory ${NAGIOS_HOME}/etc/okconfig/examples" >> /etc/okconfig.conf
224229
- echo "destination_directory ${NAGIOS_HOME}/etc/okconfig" >> /etc/okconfig.conf
225230
- mkdir -p ${NAGIOS_HOME}/etc/okconfig/templates ${NAGIOS_HOME}/etc/okconfig/examples
226-
- cp -r /usr/share/okconfig/templates/* ${NAGIOS_HOME}/etc/okconfig/templates/
227-
- cp -r /usr/share/okconfig/examples/* ${NAGIOS_HOME}/etc/okconfig/examples/
231+
- cp -r ~/build/opinkerfi/okconfig/usr/share/okconfig/templates/* ${NAGIOS_HOME}/etc/okconfig/templates/
232+
- cp -r ~/build/opinkerfi/okconfig/usr/share/okconfig/examples/* ${NAGIOS_HOME}/etc/okconfig/examples/
228233
- pynag config --append cfg_dir=${NAGIOS_HOME}/etc/okconfig
229-
- ls -l ${NAGIOS_HOME}/etc/okconfig
234+
- ls -l ${NAGIOS_HOME}/etc/okconfig
230235

231236
# Configure Adagios
232237
- pynag config --append "broker_module=/usr/local/nagios/lib/mk-livestatus/livestatus.o /usr/local/nagios/var/rw/live"
@@ -256,7 +261,7 @@ script:
256261
- cd ~/build/opinkerfi/adagios/adagios
257262
- ls -l ${NAGIOS_HOME}
258263
- nagios -v ${NAGIOS_HOME}/etc/nagios.cfg
259-
- okconfig verify
264+
#- okconfig verify
260265
- coverage run --source=adagios manage.py test
261266
after_success: coveralls
262267
notifications:

.vscode/launch.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python: Django Runserver",
9+
"type": "python",
10+
"request": "launch",
11+
"program": "${workspaceFolder}/adagios/manage.py",
12+
"args": [
13+
"runserver"
14+
],
15+
"django": true
16+
},
17+
{
18+
"name": "Python: Django Tests",
19+
"type": "python",
20+
"request": "launch",
21+
"program": "${workspaceFolder}/adagios/manage.py",
22+
"args": [
23+
"test"
24+
],
25+
"django": true
26+
}
27+
]
28+
}

adagios/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import os.path
1919

20-
__version__ = '1.6.6'
20+
__version__ = '2.0.1'
2121

2222
notifications = {}
2323
active_plugins = {}
@@ -63,7 +63,7 @@ def add_plugin(name="myplugin", modulepath=None):
6363
# will successfully start up if any of the plugins have errors
6464
try:
6565
from adagios import settings
66-
for k,v in settings.plugins.items():
66+
for k,v in list(settings.plugins.items()):
6767
try:
6868
add_plugin(k,v)
6969
except Exception:

adagios/auth.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
2020
"""
2121

22+
from builtins import str
23+
from builtins import object
2224
import adagios.status.utils
2325
import adagios.views
2426

@@ -186,5 +188,5 @@ def process_view(self, request, view_func, view_args, view_kwargs):
186188
try:
187189
path = module_name + '.' + function_name
188190
check_access_to_path(request, path)
189-
except adagios.exceptions.AccessDenied, e:
191+
except adagios.exceptions.AccessDenied as e:
190192
return adagios.views.http_403(request, exception=e)

adagios/bi/__init__.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import division
12
# Adagios is a web based Nagios configuration interface
23
#
34
# Copyright (C) 2014, Pall Sigurdsson <palli@opensource.is>
@@ -15,6 +16,9 @@
1516
# You should have received a copy of the GNU Affero General Public License
1617
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1718

19+
from builtins import str
20+
from builtins import object
21+
from past.utils import old_div
1822
from pynag.Utils import PynagError, defaultdict
1923

2024
__author__ = 'palli'
@@ -122,7 +126,7 @@ def get_status(self):
122126
self.errors.append(
123127
_("We have not implemented how to use status method %s") % str(self.status_method))
124128
return 3
125-
except Exception, e:
129+
except Exception as e:
126130
self.errors.append(e)
127131
return 3
128132

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

138142
def get_all_states(self):
139143
""" Returns a list of all subprocess states """
140-
return map(lambda x: x.get_status(), self.get_processes())
144+
return [x.get_status() for x in self.get_processes()]
141145

142146
def get_worst_state(self):
143147
""" Returns the worst state of any sub items
144148
"""
145149
try:
146150
return int(max(self.get_all_states()))
147-
except Exception, e:
151+
except Exception as e:
148152
self.errors.append(e)
149153
return 3
150154

@@ -153,7 +157,7 @@ def get_best_state(self):
153157
"""
154158
try:
155159
return int(min(self.get_all_states()))
156-
except Exception, e:
160+
except Exception as e:
157161
self.errors.append(e)
158162
return 3
159163

@@ -191,7 +195,7 @@ def run_business_rules(self):
191195
states = tags[tag]
192196

193197
# Filter out states ok
194-
states = filter(lambda x: x > 0, states)
198+
states = [x for x in states if x > 0]
195199
if not states: # Nothing more to do
196200
continue
197201
if len(states) >= num_problems:
@@ -255,7 +259,7 @@ def resolve_macrostring(self, string):
255259
all_macros = self.resolve_all_macros()
256260
try:
257261
return string.format(**all_macros)
258-
except KeyError, e:
262+
except KeyError as e:
259263
raise PynagError(_("Invalid macro in string. %s") % str(e))
260264

261265
def resolve_macro(self, macroname, default='raise exception'):
@@ -288,23 +292,23 @@ def resolve_macro(self, macroname, default='raise exception'):
288292
elif macroname == 'percent_state_0':
289293
if len(self.get_all_states()) == 0:
290294
return 0
291-
return 100.0 * state_summary[0] / sum(state_summary)
295+
return old_div(100.0 * state_summary[0], sum(state_summary))
292296
elif macroname == 'percent_state_1':
293297
if len(self.get_all_states()) == 0:
294298
return 0
295-
return 100.0 * state_summary[1] / sum(state_summary)
299+
return old_div(100.0 * state_summary[1], sum(state_summary))
296300
elif macroname == 'percent_state_2':
297301
if len(self.get_all_states()) == 0:
298302
return 0
299-
return 100.0 * state_summary[2] / sum(state_summary)
303+
return old_div(100.0 * state_summary[2], sum(state_summary))
300304
elif macroname == 'percent_state_3':
301305
if len(self.get_all_states()) == 0:
302306
return 0
303-
return 100.0 * state_summary[3] / sum(state_summary)
307+
return old_div(100.0 * state_summary[3], sum(state_summary))
304308
elif macroname == 'percent_problems':
305309
if len(self.get_all_states()) == 0:
306310
return 0
307-
return 100.0 * sum(state_summary[1:]) / sum(state_summary)
311+
return old_div(100.0 * sum(state_summary[1:]), sum(state_summary))
308312
elif macroname == 'current_state':
309313
return self.get_status()
310314
elif macroname == 'friendly_state':
@@ -372,8 +376,7 @@ def remove_pnp_graph(self, host_name, service_description, metric_name):
372376
data['metric_name'] = metric_name
373377
if not self.graphs:
374378
return
375-
self.graphs = filter(
376-
lambda x: frozenset(x) != frozenset(data), self.graphs)
379+
self.graphs = [x for x in self.graphs if frozenset(x) != frozenset(data)]
377380

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

@@ -583,11 +586,8 @@ def get_processes(self):
583586
else:
584587
services = self._livestatus.get_services(
585588
'Filter: host_groups >= %s' % self.name)
586-
livestatus_objects = map(
587-
lambda x: [x.get('host_name') + '/' + x.get(
588-
'description'), x.get('state')],
589-
services
590-
)
589+
livestatus_objects = [[x.get('host_name') + '/' + x.get(
590+
'description'), x.get('state')] for x in services]
591591
for i in livestatus_objects:
592592
process = BusinessProcess(i[0])
593593
process.get_status = lambda: i[1]
@@ -667,7 +667,7 @@ def get_status(self):
667667
try:
668668
self.load()
669669
return self._service.get('state', 3)
670-
except Exception, e:
670+
except Exception as e:
671671
self.errors.append(e)
672672
return 3
673673

@@ -687,7 +687,7 @@ def load(self):
687687
def get_status(self):
688688
try:
689689
self.load()
690-
except Exception, e:
690+
except Exception as e:
691691
self.errors.append(e)
692692
return 3
693693
method = self.status_method
@@ -753,7 +753,7 @@ def create_host(self):
753753
self.host_not_found = True
754754
self.errors.append(_("Host not found: ") % self.name)
755755
all_hosts = pynag.Model.Host.objects.all
756-
all_hosts = map(lambda x: x.host_name, all_hosts)
756+
all_hosts = [x.host_name for x in all_hosts]
757757
if self.name not in all_hosts:
758758
host = pynag.Model.Host(use="generic-domain", host_name=self.name, address=self.name)
759759
host.action_url = "http://%s" % self.name
@@ -819,7 +819,7 @@ def get_all_json(filename=None):
819819
raw_data = None
820820
try:
821821
raw_data = open(filename, 'r').read()
822-
except IOError, e:
822+
except IOError as e:
823823
if e.errno == 2: # File does not exist
824824
return []
825825
if not raw_data:
@@ -834,7 +834,7 @@ def get_all_processes(filename=None):
834834
result = []
835835
try:
836836
json_data = get_all_json(filename=filename)
837-
except IOError, e:
837+
except IOError as e:
838838
if e.errno == 2:
839839
json_data = []
840840
else:
@@ -848,7 +848,7 @@ def get_all_processes(filename=None):
848848
def get_all_process_names(filename=None):
849849
""" Return a list of all process names out there
850850
"""
851-
return map(lambda x: x.name, get_all_processes(filename=filename))
851+
return [x.name for x in get_all_processes(filename=filename)]
852852

853853

854854
def get_business_process(process_name, process_type=None, **kwargs):
@@ -862,13 +862,13 @@ def get_business_process(process_name, process_type=None, **kwargs):
862862
my_business_process = BPClass(process_name)
863863
try:
864864
my_business_process.load()
865-
except Exception, e:
865+
except Exception as e:
866866
my_business_process.errors.append(e)
867867
my_business_process.data.update(kwargs)
868868
return my_business_process
869869

870870

871-
class PNP4NagiosGraph:
871+
class PNP4NagiosGraph(object):
872872

873873
""" Represents one single PNP 4 nagios graph
874874
"""
@@ -885,5 +885,5 @@ def get_image_urls(self):
885885
'json', host=self.host_name, srv=self.service_description)
886886
graphs = json.loads(json_str)
887887
# only use graphs with same label
888-
graphs = filter(lambda x: x['ds_name'] == self.label, graphs)
888+
graphs = [x for x in graphs if x['ds_name'] == self.label]
889889
return graphs

adagios/bi/forms.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ def save(self):
4141
self.bp.remove_process(process_name, process_type)
4242
self.bp.save()
4343

44-
status_method_choices = map(
45-
lambda x: (x, x), adagios.bi.BusinessProcess.status_calculation_methods)
44+
status_method_choices = [(x, x) for x in adagios.bi.BusinessProcess.status_calculation_methods]
4645

4746

4847
class BusinessProcessForm(forms.Form):
@@ -121,7 +120,7 @@ def add_process(self):
121120
self.bp.save()
122121

123122
choices = 'businessprocess', 'hostgroup', 'servicegroup', 'service', 'host'
124-
process_type_choices = map(lambda x: (x, x), choices)
123+
process_type_choices = [(x, x) for x in choices]
125124

126125

127126
class AddSubProcess(forms.Form):

0 commit comments

Comments
 (0)