nagios-charmers team mailing list archive
-
nagios-charmers team
-
Mailing list archive
-
Message #00678
[Merge] ~aluria/hw-health-charm/+git/hw-health-charm:bug/1852945 into hw-health-charm:master
Alvaro Uria has proposed merging ~aluria/hw-health-charm/+git/hw-health-charm:bug/1852945 into hw-health-charm:master.
Requested reviews:
Nagios Charm developers (nagios-charmers)
For more details, see:
https://code.launchpad.net/~aluria/hw-health-charm/+git/hw-health-charm/+merge/375671
--
Your team Nagios Charm developers is requested to review the proposed merge of ~aluria/hw-health-charm/+git/hw-health-charm:bug/1852945 into hw-health-charm:master.
diff --git a/src/files/megacli/check_megacli.py b/src/files/megacli/check_megacli.py
index 364a654..ab3d99f 100755
--- a/src/files/megacli/check_megacli.py
+++ b/src/files/megacli/check_megacli.py
@@ -87,7 +87,7 @@ def parse_output(policy=False):
if len(errors) > 0:
msg = ', '.join([
'{}({})'.format(cnt, vars()[cnt])
- for cnt in ('failed_ld', 'wrg_policy_ld') if vars()['cnt'] > 0
+ for cnt in ('failed_ld', 'wrg_policy_ld') if vars().get(cnt, 0) > 0
])
msg += '; '.join(errors)
else:
diff --git a/src/tests/hw-health-samples/megacli.output.nrpe.critical.1 b/src/tests/hw-health-samples/megacli.output.nrpe.critical.1
new file mode 100644
index 0000000..ee557b9
--- /dev/null
+++ b/src/tests/hw-health-samples/megacli.output.nrpe.critical.1
@@ -0,0 +1,135 @@
+
+
+Adapter 0 -- Virtual Drive Information:
+Virtual Drive: 0 (Target Id: 0)
+Name :
+RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
+Size : 3.637 TB
+Sector Size : 512
+Is VD emulated : Yes
+Mirror Data : 3.637 TB
+State : Degraded
+Strip Size : 64 KB
+Number Of Drives : 2
+Span Depth : 1
+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Default Access Policy: Read/Write
+Current Access Policy: Read/Write
+Disk Cache Policy : Disk's Default
+Encryption Type : None
+Default Power Savings Policy: Controller Defined
+Current Power Savings Policy: None
+Can spin up in 1 minute: Yes
+LD has drives that support T10 power conditions: No
+LD's IO profile supports MAX power savings with cached writes: No
+Bad Blocks Exist: No
+Is VD Cached: No
+
+
+Virtual Drive: 1 (Target Id: 1)
+Name :
+RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0
+Size : 3.637 TB
+Sector Size : 512
+Is VD emulated : No
+Parity Size : 0
+State : Optimal
+Strip Size : 64 KB
+Number Of Drives : 1
+Span Depth : 1
+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Default Access Policy: Read/Write
+Current Access Policy: Read/Write
+Disk Cache Policy : Disk's Default
+Encryption Type : None
+Default Power Savings Policy: Controller Defined
+Current Power Savings Policy: None
+Can spin up in 1 minute: Yes
+LD has drives that support T10 power conditions: No
+LD's IO profile supports MAX power savings with cached writes: No
+Bad Blocks Exist: No
+Is VD Cached: No
+
+
+Virtual Drive: 2 (Target Id: 2)
+Name :
+RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0
+Size : 3.637 TB
+Sector Size : 512
+Is VD emulated : No
+Parity Size : 0
+State : Optimal
+Strip Size : 64 KB
+Number Of Drives : 1
+Span Depth : 1
+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Default Access Policy: Read/Write
+Current Access Policy: Read/Write
+Disk Cache Policy : Disk's Default
+Encryption Type : None
+Default Power Savings Policy: Controller Defined
+Current Power Savings Policy: None
+Can spin up in 1 minute: Yes
+LD has drives that support T10 power conditions: No
+LD's IO profile supports MAX power savings with cached writes: No
+Bad Blocks Exist: No
+Is VD Cached: No
+
+
+Virtual Drive: 3 (Target Id: 3)
+Name :
+RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0
+Size : 3.637 TB
+Sector Size : 512
+Is VD emulated : No
+Parity Size : 0
+State : Optimal
+Strip Size : 64 KB
+Number Of Drives : 1
+Span Depth : 1
+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Default Access Policy: Read/Write
+Current Access Policy: Read/Write
+Disk Cache Policy : Disk's Default
+Encryption Type : None
+Default Power Savings Policy: Controller Defined
+Current Power Savings Policy: None
+Can spin up in 1 minute: Yes
+LD has drives that support T10 power conditions: No
+LD's IO profile supports MAX power savings with cached writes: No
+Bad Blocks Exist: No
+Is VD Cached: No
+
+
+Virtual Drive: 4 (Target Id: 4)
+Name :
+RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0
+Size : 3.637 TB
+Sector Size : 512
+Is VD emulated : No
+Parity Size : 0
+State : Optimal
+Strip Size : 64 KB
+Number Of Drives : 1
+Span Depth : 1
+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Default Access Policy: Read/Write
+Current Access Policy: Read/Write
+Disk Cache Policy : Disk's Default
+Encryption Type : None
+Default Power Savings Policy: Controller Defined
+Current Power Savings Policy: None
+Can spin up in 1 minute: Yes
+LD has drives that support T10 power conditions: No
+LD's IO profile supports MAX power savings with cached writes: No
+Bad Blocks Exist: No
+Is VD Cached: No
+
+
+
+Exit Code: 0x00
diff --git a/src/tests/hw-health-samples/megacli.output.nrpe.critical.2 b/src/tests/hw-health-samples/megacli.output.nrpe.critical.2
new file mode 100644
index 0000000..d0ee574
--- /dev/null
+++ b/src/tests/hw-health-samples/megacli.output.nrpe.critical.2
@@ -0,0 +1,135 @@
+
+
+Adapter 0 -- Virtual Drive Information:
+Virtual Drive: 0 (Target Id: 0)
+Name :
+RAID Level : Primary-1, Secondary-0, RAID Level Qualifier-0
+Size : 3.637 TB
+Sector Size : 512
+Is VD emulated : Yes
+Mirror Data : 3.637 TB
+State : Degraded
+Strip Size : 64 KB
+Number Of Drives : 2
+Span Depth : 1
+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Default Access Policy: Read/Write
+Current Access Policy: Read/Write
+Disk Cache Policy : Disk's Default
+Encryption Type : None
+Default Power Savings Policy: Controller Defined
+Current Power Savings Policy: None
+Can spin up in 1 minute: Yes
+LD has drives that support T10 power conditions: No
+LD's IO profile supports MAX power savings with cached writes: No
+Bad Blocks Exist: No
+Is VD Cached: No
+
+
+Virtual Drive: 1 (Target Id: 1)
+Name :
+RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0
+Size : 3.637 TB
+Sector Size : 512
+Is VD emulated : No
+Parity Size : 0
+State : Optimal
+Strip Size : 64 KB
+Number Of Drives : 1
+Span Depth : 1
+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Default Access Policy: Read/Write
+Current Access Policy: Read/Write
+Disk Cache Policy : Disk's Default
+Encryption Type : None
+Default Power Savings Policy: Controller Defined
+Current Power Savings Policy: None
+Can spin up in 1 minute: Yes
+LD has drives that support T10 power conditions: No
+LD's IO profile supports MAX power savings with cached writes: No
+Bad Blocks Exist: No
+Is VD Cached: No
+
+
+Virtual Drive: 2 (Target Id: 2)
+Name :
+RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0
+Size : 3.637 TB
+Sector Size : 512
+Is VD emulated : No
+Parity Size : 0
+State : Optimal
+Strip Size : 64 KB
+Number Of Drives : 1
+Span Depth : 1
+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Default Access Policy: Read/Write
+Current Access Policy: Read/Write
+Disk Cache Policy : Disk's Default
+Encryption Type : None
+Default Power Savings Policy: Controller Defined
+Current Power Savings Policy: None
+Can spin up in 1 minute: Yes
+LD has drives that support T10 power conditions: No
+LD's IO profile supports MAX power savings with cached writes: No
+Bad Blocks Exist: No
+Is VD Cached: No
+
+
+Virtual Drive: 3 (Target Id: 3)
+Name :
+RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0
+Size : 3.637 TB
+Sector Size : 512
+Is VD emulated : No
+Parity Size : 0
+State : Optimal
+Strip Size : 64 KB
+Number Of Drives : 1
+Span Depth : 1
+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Default Access Policy: Read/Write
+Current Access Policy: Read/Write
+Disk Cache Policy : Disk's Default
+Encryption Type : None
+Default Power Savings Policy: Controller Defined
+Current Power Savings Policy: None
+Can spin up in 1 minute: Yes
+LD has drives that support T10 power conditions: No
+LD's IO profile supports MAX power savings with cached writes: No
+Bad Blocks Exist: No
+Is VD Cached: No
+
+
+Virtual Drive: 4 (Target Id: 4)
+Name :
+RAID Level : Primary-0, Secondary-0, RAID Level Qualifier-0
+Size : 3.637 TB
+Sector Size : 512
+Is VD emulated : No
+Parity Size : 0
+State : Degraded
+Strip Size : 64 KB
+Number Of Drives : 1
+Span Depth : 1
+Default Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Current Cache Policy: WriteBack, ReadAhead, Direct, No Write Cache if Bad BBU
+Default Access Policy: Read/Write
+Current Access Policy: Read/Write
+Disk Cache Policy : Disk's Default
+Encryption Type : None
+Default Power Savings Policy: Controller Defined
+Current Power Savings Policy: None
+Can spin up in 1 minute: Yes
+LD has drives that support T10 power conditions: No
+LD's IO profile supports MAX power savings with cached writes: No
+Bad Blocks Exist: No
+Is VD Cached: No
+
+
+
+Exit Code: 0x00
diff --git a/src/tests/unit/test_check_megacli.py b/src/tests/unit/test_check_megacli.py
index d2e21c4..988075a 100644
--- a/src/tests/unit/test_check_megacli.py
+++ b/src/tests/unit/test_check_megacli.py
@@ -4,6 +4,8 @@ import sys
import unittest
import unittest.mock as mock
+import nagios_plugin3
+
sys.path.append('files/megacli')
import check_megacli # noqa: E402
@@ -17,3 +19,22 @@ class TestCheckMegaCLI(unittest.TestCase):
actual = mock_print.getvalue()
expected = 'OK: Optimal, ldrives[1], pdrives[4]\n'
self.assertEqual(actual, expected)
+
+ @mock.patch('sys.stdout', new_callable=io.StringIO)
+ def test_parse_output_critical_singledrive(self, mock_print):
+ check_megacli.INPUT_FILE = os.path.join(
+ os.getcwd(), 'tests', 'hw-health-samples', 'megacli.output.nrpe.critical.1')
+ expected = 'CRITICAL: adapter(0):ld(0):state(Degraded)'
+ with self.assertRaises(nagios_plugin3.CriticalError) as context:
+ check_megacli.parse_output()
+ self.assertEqual(expected, str(context.exception))
+
+ @mock.patch('sys.stdout', new_callable=io.StringIO)
+ def test_parse_output_critical_multiple(self, mock_print):
+ check_megacli.INPUT_FILE = os.path.join(
+ os.getcwd(), 'tests', 'hw-health-samples', 'megacli.output.nrpe.critical.2')
+ expected = ('CRITICAL: adapter(0):ld(0):state(Degraded);'
+ ' adapter(0):ld(4):state(Degraded)')
+ with self.assertRaises(nagios_plugin3.CriticalError) as context:
+ check_megacli.parse_output()
+ self.assertEqual(expected, str(context.exception))
Follow ups