Skip to content

Commit

Permalink
Adding 201 SR Template for
Browse files Browse the repository at this point in the history
  • Loading branch information
switschel committed Sep 21, 2023
1 parent 2322e04 commit 5f06d44
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
11 changes: 6 additions & 5 deletions c8ydm/agentmodules/device_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ def getMessages(self):
self.logger.exception(f'Error in DeviceSensor getMessages: {e}', e)

def sendStats(self):
self.stats = []
stats = ['c8y_deviceStats','']
#201,KamstrupA220Reading,2022-03-19T12:03:27.845Z,c8y_SinglePhaseEnergyMeasurement,A+:1,1234,kWh,c8y_SinglePhaseEnergyMeasurement,A-:1,2345,kWh,c8y_ThreePhaseEnergyMeasurement,A+:1,123,kWh,c8y_ThreePhaseEnergyMeasurement,A+:2,234,kWh,c8y_ThreePhaseEnergyMeasurement,A+:3,345,kWh
for key,value in self._getCPU().items():
self.stats.append(SmartRESTMessage('s/us', '200', ['cpu', key, value]))
stats.extend(['cpu', key, value, '' ])
for key,value in self._getDisk().items():
self.stats.append(SmartRESTMessage('s/us', '200', ['disk', key, value]))
stats.extend(['disk', key, value, '' ])
for key,value in self._getMemory().items():
self.stats.append(SmartRESTMessage('s/us', '200', ['memory', key, value]))
return self.stats
stats.extend(['memory', key, value, '' ])
return [SmartRESTMessage('s/us', '201', stats)]

def _getCPU(self):
return self.DeviceStats.getCPUStats()
Expand Down
12 changes: 7 additions & 5 deletions c8ydm/agentmodules/docker_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ def getSensorMessages(self):
#self.logger.info(f'Docker Update Loop called...')
payload = self.docker_watcher.get_stats()
service_msgs = []

if payload is not None:
if self.agent.token_received.wait(timeout=self.agent.refresh_token_interval):
internal_id = self.agent.rest_client.get_internal_id(self.agent.serial)
self.agent.rest_client.update_managed_object(internal_id, json.dumps(payload))

for container in payload['c8y_Docker']:
try:
service_measurements = ['ResourceUsage','']
container_id = f'{self.serial}_{container["containerID"]}'
container_name = container['name']
container_status = container['status']
Expand All @@ -56,13 +58,13 @@ def getSensorMessages(self):
update_msg = SmartRESTMessage(f's/us/{container_id}', '104', [status])
service_msgs.append(update_msg)
if container_cpu:
cpu_msg = SmartRESTMessage(f's/us/{container_id}', '200', ['ResourceUsage', 'cpu', container_cpu, '%'])
service_msgs.append(cpu_msg)
service_measurements.extend(['ResourceUsage', 'cpu', container_cpu, '%'])
if container_memory:
memory_msg = SmartRESTMessage(f's/us/{container_id}', '200', ['ResourceUsage', 'memory', container_memory, '%'])
service_msgs.append(memory_msg)
service_measurements.extend(['ResourceUsage', 'memory', container_memory, '%'])
if len(service_measurements) > 2:
service_msgs.append(SmartRESTMessage(f's/us/{container_id}', '201', service_measurements))
except Exception as ex:
self.logger(f'Error in Docker Watcher Sensor Messages: {ex}')
self.logger.error(f'Error in Docker Watcher Sensor Messages: {ex}')

return service_msgs

Expand Down
10 changes: 6 additions & 4 deletions c8ydm/agentmodules/software_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,12 @@ def handleOperation(self, message):
self.agent.publishMessage(failed)

def getSupportedOperations(self):
if self.agent.token_received.wait(timeout=self.agent.refresh_token_interval):
supported_sw_types = { 'c8y_SupportedSoftwareTypes': ['apt']}
mo_id = self.agent.rest_client.get_internal_id(self.agent.serial)
self.agent.rest_client.update_managed_object(mo_id, json.dumps(supported_sw_types))
self.agent.publishMessage(SmartRESTMessage('s/us', '143', ['apt']))
# Deprecated since 1017
# if self.agent.token_received.wait(timeout=self.agent.refresh_token_interval):
# supported_sw_types = { 'c8y_SupportedSoftwareTypes': ['apt']}
# mo_id = self.agent.rest_client.get_internal_id(self.agent.serial)
# self.agent.rest_client.update_managed_object(mo_id, json.dumps(supported_sw_types))
return ['c8y_SoftwareUpdate', 'c8y_SoftwareList']

def getSupportedTemplates(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
name='c8ydm',
long_description=long_description,
long_description_content_type="text/markdown",
version='1.3.6',
version='1.3.7',
description='Cumulocity Device Management Agent',
author='Tobias Sommer, Stefan Witschel, Marco Stoffel, Murat Bayram',
author_email="Stefan.Witschel@softwareag.com",
Expand Down

0 comments on commit 5f06d44

Please sign in to comment.