Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tasks/getval.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"input_method": "stdin",
"files": ["python_task_helper/files/task_helper.py"],
"parameters": {
"hostname": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi
There's example and parameters in README that could be extended with the new option.

"description": "Hostname of metric, as configured with Hostname in collectd",
"type": "Optional[String[1]]"
},
"metric": {
"description": "Name of metric, e.g. load/load-relative",
"type": "String[1]"
Expand Down
19 changes: 16 additions & 3 deletions tasks/getval.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,24 @@
from task_helper import TaskHelper


HOSTNAME = socket.gethostname()
class GetVal(TaskHelper):
def get_metric(self, hostname, metric):
fullmetric = hostname+'/'+metric
return subprocess.check_output(['/usr/bin/collectdctl', 'getval',fullmetric]).rstrip().decode().split('\n')

def task(self, args):
fullmetric = HOSTNAME+'/'+args['metric']
results = subprocess.check_output(['/usr/bin/collectdctl', 'getval',fullmetric]).rstrip().decode().split('\n')
if 'hostname' in args:
hosts = [args['hostname']]
else:
hosts = [socket.gethostname(), socket.getfqdn()]

for host in hosts:
try:
results = self.get_metric(host, args['metric'])
break
except:
continue

values = { k:v for k,v in (x.split('=') for x in results)}
return {
'metric': args['metric'],
Expand Down