Skip to content
This repository has been archived by the owner on Oct 25, 2019. It is now read-only.

Commit

Permalink
Release 0.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ralph089 committed May 16, 2017
1 parent 98d0a51 commit 3955891
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 48 deletions.
6 changes: 5 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
History
-------
0.3.2 (2017-16-05)
------------------
* Fixed issue #8: Measuring throughput on multiple identically configured PA's fails

0.3.1 (2017-10-03)
------------------

Expand All @@ -10,7 +14,7 @@ History
* Removed the the unit of measurement (UOM) for throughput command

0.3 (2017-27-02)
------------------
----------------

* Support for Python 3.5 added
* Minor code improvements
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ It is written in Python and based on the PA REST API.
Tested on:

- PA-500 v6.0.1 - v6.0.9
- PA-3050 v6.0.9 - 7.0.9
- PA-3050 v6.0.9 - 7.1.9

.. image:: https://travis-ci.org/ralph-hm/nagios_check_paloalto.svg?branch=master
:target: https://travis-ci.org/ralph-hm/nagios_check_paloalto?branch=master

.. image:: https://coveralls.io/repos/github/ralph-hm/nagios_check_paloalto/badge.svg?branch=master
:target: https://coveralls.io/github/ralph-hm/nagios_check_paloalto?branch=master

Expand Down
2 changes: 1 addition & 1 deletion check_pa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = 'Ralph Offinger'
__email__ = '[email protected]'
__version__ = '0.3.1'
__version__ = '0.3.2'
2 changes: 1 addition & 1 deletion check_pa/check_paloalto.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def parse_args(args):

info = parser.add_argument_group('Info')
info.add_argument('--version', action='version',
version='%(prog)s 0.3.1')
version='%(prog)s 0.3.2')

subparsers = parser.add_subparsers(dest='command')
subparsers.required = True
Expand Down
12 changes: 6 additions & 6 deletions check_pa/modules/throughput.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ def probe(self):
_log.debug('Path to statefile: %r' % get_statefile_path())
with np.Cookie(get_statefile_path()) as cookie:

old_inbytes = cookie.get(self.interface_name + 'i', api_inbytes)
old_outbytes = cookie.get(self.interface_name + 'o', api_outbytes)
old_time = cookie.get(self.interface_name + 't', current_time)
old_inbytes = cookie.get(self.host + self.interface_name + 'i', api_inbytes)
old_outbytes = cookie.get(self.host + self.interface_name + 'o', api_outbytes)
old_time = cookie.get(self.host + self.interface_name + 't', current_time)

if not api_inbytes or not api_outbytes or float(api_inbytes) < 0 or float(api_outbytes) < 0:
raise np.CheckError('Couldn\'t get a valid value!')

cookie[self.interface_name + 'i'] = api_inbytes
cookie[self.interface_name + 'o'] = api_outbytes
cookie[self.interface_name + 't'] = current_time
cookie[self.host + self.interface_name + 'i'] = api_inbytes
cookie[self.host + self.interface_name + 'o'] = api_outbytes
cookie[self.host + self.interface_name + 't'] = current_time

if float(api_inbytes) < float(old_inbytes) or float(api_outbytes) < float(old_outbytes):
raise np.CheckError('Couldn\'t get a valid value: Found throughput less then old!')
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
]

setup(name='check_paloalto',
version='0.3.1',
version='0.3.2',
description="check_paloalto is a Nagios/Icinga plugin for Palo Alto Next Generation Firewalls. It is written in "
"Python and based on the PA REST API.",
long_description=readme + '\n\n' + history,
Expand Down
141 changes: 105 additions & 36 deletions tests/test_throughput.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ def test_with_three_interfaces(self, statefile):

# Resetting cookies
with Cookie(statefile) as cookie:
cookie[interfaces[0] + 'i'] = 0
cookie[interfaces[0] + 'o'] = 0
cookie[interfaces[0] + 't'] = 1441324800
cookie[interfaces[1] + 'i'] = 0
cookie[interfaces[1] + 'o'] = 0
cookie[interfaces[1] + 't'] = 1441324800
cookie[interfaces[2] + 'i'] = 0
cookie[interfaces[2] + 'o'] = 0
cookie[interfaces[2] + 't'] = 1441324800
cookie[self.host + interfaces[0] + 'i'] = 0
cookie[self.host + interfaces[0] + 'o'] = 0
cookie[self.host + interfaces[0] + 't'] = 1441324800
cookie[self.host + interfaces[1] + 'i'] = 0
cookie[self.host + interfaces[1] + 'o'] = 0
cookie[self.host + interfaces[1] + 't'] = 1441324800
cookie[self.host + interfaces[2] + 'i'] = 0
cookie[self.host + interfaces[2] + 'o'] = 0
cookie[self.host + interfaces[2] + 't'] = 1441324800

# Check will be executed exactly one second later
now = 1441324801
Expand Down Expand Up @@ -107,8 +107,8 @@ def test_with_one_interface(self, statefile):

check = check_pa.modules.throughput.create_check(self)
objects = []
for ressource in check.resources:
objects.append(ressource)
for res in check.resources:
objects.append(res)

with responses.RequestsMock() as rsps:

Expand All @@ -122,9 +122,9 @@ def test_with_one_interface(self, statefile):
from nagiosplugin import Cookie

with Cookie(statefile) as cookie:
cookie[interfaces[0] + 'i'] = 0
cookie[interfaces[0] + 'o'] = 0
cookie[interfaces[0] + 't'] = 1441324800
cookie[self.host + interfaces[0] + 'i'] = 0
cookie[self.host + interfaces[0] + 'o'] = 0
cookie[self.host + interfaces[0] + 't'] = 1441324800

# Check will be executed exactly ten seconds later
now = 1441324810
Expand All @@ -143,6 +143,76 @@ def test_with_one_interface(self, statefile):
assert check.summary_str == 'Input is 0.8 Mb/s - Output is 0.8 ' \
'Mb/s'

def check_pa(self, time, ibytes, obytes, filename):
objects = []
file1 = filename

check = check_pa.modules.throughput.create_check(self)

for res in check.resources:
objects.append(res)

with responses.RequestsMock() as rsps:
rsps.add(responses.GET,
objects[0].xml_obj.build_request_url(),
body=utils.read_xml(file1),
status=200,
content_type='document',
match_querystring=True)

with mock.patch('check_pa.modules.throughput.get_time',
return_value=time):
with mock.patch('check_pa.xml_reader.Finder.find_item',
side_effect=[ibytes, obytes]):
with pytest.raises(SystemExit):
check.main(verbose=3)

return check

@responses.activate
def test_with_different_ips(self, statefile):

pa_1 = self.__class__()
pa_1.host = "192.168.0.1"
pa_1.interface = "ethernet1/1"

pa_2 = self.__class__()
pa_2.host = "192.168.0.2"
pa_2.interface = "ethernet1/1"

from nagiosplugin import Cookie

with Cookie(statefile) as cookie:
cookie[pa_1.host + pa_1.interface + 'i'] = 0
cookie[pa_1.host + pa_1.interface + 'o'] = 0
cookie[pa_1.host + pa_1.interface + 't'] = 1441324800

check = pa_1.check_pa(1441324800, 10, 10, "throughput1.xml")

assert check.exitcode == 3
assert check.state == ServiceState(code=3, text='unknown')
assert check.summary_str == 'Difference between old timestamp and new timestamp is less or equal 0: If it is the first time you run the script, please execute it again!'

check = pa_2.check_pa(1441324810, 110, 110, "throughput1.xml")

assert check.exitcode == 3
assert check.state == ServiceState(code=3, text='unknown')
assert check.summary_str == 'Difference between old timestamp and new timestamp is less or equal 0: If it is the first time you run the script, please execute it again!'

check = pa_1.check_pa(1441324801, 1000000, 1000000, "throughput1.xml")
assert check.exitcode == 0
assert check.state == ServiceState(code=0, text='ok')
# 1000000 Byte = 1 MByte = 8 Mbit in 1 second = 8.0 Mb/s
assert check.summary_str == 'Input is 8.0 Mb/s - Output is 8.0 ' \
'Mb/s'

check = pa_2.check_pa(1441324811, 1000000, 1000000, "throughput1.xml")
assert check.exitcode == 0
assert check.state == ServiceState(code=0, text='ok')
# 1000000 Byte = 1 MByte = 8 Mbit in 1 second = 8.0 Mb/s
assert check.summary_str == 'Input is 8.0 Mb/s - Output is 8.0 ' \
'Mb/s'

@responses.activate
def test_new_input_less_than_old(self, statefile):
file1 = 'throughput1.xml'
Expand All @@ -154,8 +224,8 @@ def test_new_input_less_than_old(self, statefile):

check = check_pa.modules.throughput.create_check(self)
objects = []
for ressource in check.resources:
objects.append(ressource)
for res in check.resources:
objects.append(res)

with responses.RequestsMock() as rsps:

Expand All @@ -169,9 +239,9 @@ def test_new_input_less_than_old(self, statefile):
from nagiosplugin import Cookie

with Cookie(statefile) as cookie:
cookie[interfaces[0] + 'i'] = 10
cookie[interfaces[0] + 'o'] = 10
cookie[interfaces[0] + 't'] = 1441324800
cookie[self.host + interfaces[0] + 'i'] = 10
cookie[self.host + interfaces[0] + 'o'] = 10
cookie[self.host + interfaces[0] + 't'] = 1441324800

# Check will be executed exactly ten seconds later
now = 1441324810
Expand Down Expand Up @@ -200,8 +270,8 @@ def test_new_output_less_than_old(self, statefile):

check = check_pa.modules.throughput.create_check(self)
objects = []
for ressource in check.resources:
objects.append(ressource)
for res in check.resources:
objects.append(res)

with responses.RequestsMock() as rsps:

Expand All @@ -215,9 +285,9 @@ def test_new_output_less_than_old(self, statefile):
from nagiosplugin import Cookie

with Cookie(statefile) as cookie:
cookie[interfaces[0] + 'i'] = 10
cookie[interfaces[0] + 'o'] = 10
cookie[interfaces[0] + 't'] = 1441324800
cookie[self.host + interfaces[0] + 'i'] = 10
cookie[self.host + interfaces[0] + 'o'] = 10
cookie[self.host + interfaces[0] + 't'] = 1441324800

# Check will be executed exactly ten seconds later
now = 1441324810
Expand All @@ -232,9 +302,9 @@ def test_new_output_less_than_old(self, statefile):
check.main(verbose=3)

with Cookie(statefile) as cookie:
input = cookie.get(interfaces[0] + 'i')
output = cookie.get(interfaces[0] + 'o')
time = cookie.get(interfaces[0] + 't')
input = cookie.get(self.host + interfaces[0] + 'i')
output = cookie.get(self.host + interfaces[0] + 'o')
time = cookie.get(self.host + interfaces[0] + 't')

assert input == xml_ibytes
assert output == xml_obytes
Expand All @@ -244,7 +314,6 @@ def test_new_output_less_than_old(self, statefile):
assert check.state == ServiceState(code=3, text='unknown')
assert check.summary_str == 'Couldn\'t get a valid value: Found throughput less then old!'


@responses.activate
def test_same_time(self, statefile):
file1 = 'throughput1.xml'
Expand All @@ -270,9 +339,9 @@ def test_same_time(self, statefile):
from nagiosplugin import Cookie

with Cookie(statefile) as cookie:
cookie[interfaces[0] + 'i'] = 10
cookie[interfaces[0] + 'o'] = 10
cookie[interfaces[0] + 't'] = 1441324800
cookie[self.host + interfaces[0] + 'i'] = 10
cookie[self.host + interfaces[0] + 'o'] = 10
cookie[self.host + interfaces[0] + 't'] = 1441324800

# Check will be executed exactly at the same time
now = 1441324800
Expand Down Expand Up @@ -305,8 +374,8 @@ def test_api_failed(self, statefile):

check = check_pa.modules.throughput.create_check(self)
objects = []
for ressource in check.resources:
objects.append(ressource)
for res in check.resources:
objects.append(res)

with responses.RequestsMock() as rsps:

Expand All @@ -320,9 +389,9 @@ def test_api_failed(self, statefile):
from nagiosplugin import Cookie

with Cookie(statefile) as cookie:
cookie[interfaces[0] + 'i'] = 10
cookie[interfaces[0] + 'o'] = 10
cookie[interfaces[0] + 't'] = 1441324800
cookie[self.host + interfaces[0] + 'i'] = 10
cookie[self.host + interfaces[0] + 'o'] = 10
cookie[self.host + interfaces[0] + 't'] = 1441324800

# Check will be executed exactly ten seconds later
now = 1441324810
Expand Down

0 comments on commit 3955891

Please sign in to comment.