Skip to content

Commit

Permalink
17040 FIX agent_netapp_ontap: KeyError: 'used'
Browse files Browse the repository at this point in the history
SUP-20332

Change-Id: I7215a9420c469ddc21a39162c0ce8e015932db90
  • Loading branch information
racicLuka committed Oct 22, 2024
1 parent fc3b391 commit 9136efc
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
24 changes: 24 additions & 0 deletions .werks/17040.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[//]: # (werk v2)
# agent_netapp_ontap: KeyError: 'used'

key | value
---------- | ---
date | 2024-10-09T16:23:37+00:00
version | 2.3.0p20
class | fix
edition | cre
component | checks
level | 1
compatible | yes

This change affects users monitoring NetApp through the Ontap REST API. Previously
the special agent might crash with the following error
```
File "/omd/sites/IDT_Dessau/lib/python3/cmk/special_agents/agent_netapp_ontap.py", line 287, in fetch_luns
space_used=element_data["space"]["used"],
KeyError: 'used
```
If this happens now, the state of the check will be 'UNKN' and the summary will contain a suggestion that the space used is not available.

It is important to note that we have not been able to reproduce the problem where the lun volume does not provide information about how much space is used.
Therefore, other errors may occur in this scenario that cannot be addressed by this werk. Please report such problems so that we can address them.
4 changes: 4 additions & 0 deletions cmk/plugins/netapp/agent_based/netapp_ontap_luns.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def _check_netapp_ontap_luns(
yield Result(state=State.OK, summary=f"Volume: {lun.volume_name}")
yield Result(state=State.OK, summary=f"SVM: {lun.svm_name}")

if lun.space_used is None:
yield Result(state=State.UNKNOWN, summary="Space used is unknown")
return

yield from check_netapp_luns(
item=item,
online=lun.enabled,
Expand Down
4 changes: 3 additions & 1 deletion cmk/plugins/netapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class LunModel(BaseModel):

name: str
space_size: int
space_used: int
space_used: int | None = None
enabled: bool
read_only: bool
svm_name: str
Expand All @@ -210,6 +210,8 @@ def size(self) -> float:
return self.space_size / MEGA

def free_space(self) -> float:
if self.space_used is None:
raise ValueError("space_used must be available to calculate free space")
return (self.space_size - self.space_used) / MEGA

def item_name(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion cmk/special_agents/agent_netapp_ontap.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def fetch_luns(connection: HostConnection) -> Iterable[models.LunModel]:
yield models.LunModel(
name=element_data["name"],
space_size=element_data["space"]["size"],
space_used=element_data["space"]["used"],
space_used=element_data["space"].get("used"),
enabled=element_data["enabled"],
read_only=element_data["status"]["read_only"],
svm_name=element_data["svm"]["name"],
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/cmk/plugins/netapp/test_netapp_ontap_luns.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,33 @@ def test_check_netapp_luns() -> None:
Result(state=State.OK, summary="Volume: test_volume_name"),
Result(state=State.OK, summary="SVM: test_svm_name"),
]


def test_check_netapp_luns_no_used_space() -> None:
lun_model = LunModelFactory.build(
name="/vol/test/lun1",
volume_name="test_volume_name",
svm_name="test_svm_name",
space_used=None,
)
section = {lun_model.item_name(): lun_model}

result = list(
_check_netapp_ontap_luns(
"lun1",
{ # not revelevant for this test - but needed
"levels": (80.0, 90.0),
"trend_range": 24,
},
section,
# not revelevant for this test - but needed:
{"lun1.delta": (0.0, 0.0)},
0.0,
)
)

assert result == [
Result(state=State.OK, summary="Volume: test_volume_name"),
Result(state=State.OK, summary="SVM: test_svm_name"),
Result(state=State.UNKNOWN, summary="Space used is unknown"),
]

0 comments on commit 9136efc

Please sign in to comment.