Last active
December 3, 2018 22:22
-
-
Save andyshinn/ab00591ab88bebd540920c472600c947 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datadog_checks.utils.subprocess_output import get_subprocess_output | |
from datadog_checks.checks import AgentCheck | |
class AptCheck(AgentCheck): | |
def check(self, instance): | |
metric_prefix = 'package.updates' | |
package_updates = self.get_update_count() | |
self.gauge('%s.security' % metric_prefix, package_updates['security']) | |
self.gauge('%s.regular' % metric_prefix, package_updates['regular']) | |
self.gauge('%s.total' % metric_prefix, package_updates['total']) | |
def get_update_count(self): | |
check_update_path = self.init_config.get('apt_check_path', '/usr/lib/update-notifier/apt-check') | |
output, err, retcode = get_subprocess_output([check_update_path], self.log, raise_on_empty_output=True) | |
return { | |
'total': int(output[0]), | |
'regular' : int(output[0]) - int(output[1]), | |
'security': int(output[1]) | |
} | |
if __name__ == '__main__': | |
check.check(instance) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
andy@www-ws5t:~$ sudo -u dd-agent -- datadog-agent check apt_check | |
========= | |
Collector | |
========= | |
Running Checks | |
============== | |
apt_check | |
--------- | |
Total Runs: 1 | |
Metrics: 0, Total Metrics: 0 | |
Events: 0, Total Events: 0 | |
Service Checks: 0, Total Service Checks: 0Error: 'bool' object has no attribute 'debug' | |
Traceback (most recent call last): | |
File "/opt/datadog-agent/bin/agent/dist/checks/__init__.py", line 332, in run | |
self.check(copy.deepcopy(self.instances[0])) | |
File "/etc/datadog-agent/checks.d/apt_check.py", line 8, in check | |
package_updates = self.get_update_count() | |
File "/etc/datadog-agent/checks.d/apt_check.py", line 15, in get_update_count | |
output, err, retcode = get_subprocess_output([check_update_path], self.log, raise_on_empty_output=True) | |
File "/opt/datadog-agent/embedded/lib/python2.7/site-packages/datadog_checks/utils/subprocess_output.py", line 37, in get_subprocess_output | |
out, err, returncode = subprocess_output(cmd_args, raise_on_empty_output) | |
File "/opt/datadog-agent/bin/agent/dist/utils/subprocess_output.py", line 32, in get_subprocess_output | |
log.debug("Running get_subprocess_output with cmd: %s", cmd_args) | |
AttributeError: 'bool' object has no attribute 'debug' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment