Skip to content

Instantly share code, notes, and snippets.

@soudai
Last active June 4, 2017 19:03
Show Gist options
  • Save soudai/1519e9db370dff1264567d75bc706a2c to your computer and use it in GitHub Desktop.
Save soudai/1519e9db370dff1264567d75bc706a2c to your computer and use it in GitHub Desktop.
yumのインストールパッケージを雑にmackerelのmetadataとして登録する
<?php
$list = explode("\n", `yum list installed`);
foreach ($list as $key => $val) {
if (empty($val)) {
continue;
}
$base_list = array_filter(explode(" ", $val));
$json_base[$key]['name'] = array_shift($base_list);
$json_base[$key]['version'] = array_shift($base_list);
}
echo json_encode($json_base);
/**
add setting to/etc/mackerel-agent/mackerel-agent.conf
[plugin.metadata.packages]
command = "/usr/bin/php /usr/local/etc/mackerel/meta-rpm-packages.php"
get matadata sample
curl -H 'X-Api-Key: <API_KEY>' https://mackerel.io/api/v0/hosts/<hostID>/metadata/packages
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment