Skip to content

Commit

Permalink
Merge pull request #10 from dan-smalley/device_router_add_comment_fun…
Browse files Browse the repository at this point in the history
…ction

Add add_comment to device router
  • Loading branch information
dan-smalley authored Sep 3, 2024
2 parents 9945c09 + c679379 commit 9e88408
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/zenossapi/routers/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,35 @@ def get_device_class(self, device_class):
dc_data['data']
)

def add_comment_by_uid(self, device_uid, comment):
"""
Append a new comment to a device
Arguments:
device_uid (str): The uid of the device to comment on
comment (str): Text of the desired comment
Returns:
str: Response message
"""

# Get existing comments
device = self.get_device_by_uid(device_uid)
if len(device.comments) > 0:
comment = f'{device.comments}\n{comment}'

response_data = self._router_request(
self._make_request_data(
'setInfo',
dict(
uid=device_uid,
comments=comment,
)
)
)

return response_data['msg']


class ZenossDeviceClass(DeviceRouter):
"""
Expand Down Expand Up @@ -1934,6 +1963,24 @@ def set_priority(self, priority):
self.priority = priority
return message

def add_comment(self, comment):
"""
Append a comment to a device.
Arguments:
comment (str): Desired comment text
Returns:
str: Reponse message
"""

message = self.add_comment_by_uid(self.uid, comment)
if len(self.comments) > 0:
self.comments = f'{self.comments}\n{comment}'
else:
self.comments = comment


def set_collector(self, collector):
"""
Set the collector for the device.
Expand Down

0 comments on commit 9e88408

Please sign in to comment.