+ return true;
+}
+
+function _collectd_list_cb_host(&$options, $host) {
+ if ($options['cb_plugin'] === false) {
+ $options['result'][] = $host;
+ return false;
+ } else if (isset($options['filter_host'])) {
+ if ($options['filter_host'] == '@all') {
+ return true; // We take anything
+ } else if (substr($options['filter_host'], 0, 2) == '@.') {
+ if ($host == substr($options['filter_host'], 2) || substr($host, 0, 1-strlen($options['filter_host'])) == substr($options['filter_host'], 1))
+ return true; // Host part of domain
+ else
+ return false;
+ } else if ($options['filter_host'] == $host) {
+ return true;
+ } else
+ return false;
+ } else
+ return true;
+}
+
+function _collectd_list_cb_plugin(&$options, $host, $plugin) {
+ if ($options['cb_pinst'] === false) {
+ $options['result'][] = $plugin;
+ return false;
+ } else if (isset($options['filter_plugin'])) {
+ if ($options['filter_plugin'] == '@all')
+ return true;
+ else if ($options['filter_plugin'] == $plugin)
+ return true;
+ else
+ return false;
+ } else
+ return true;
+}
+
+function _collectd_list_cb_pinst(&$options, $host, $plugin, $pinst) {
+ if ($options['cb_type'] === false) {
+ $options['result'][] = $pinst;
+ return false;
+ } else if (isset($options['filter_pinst'])) {
+ if ($options['filter_pinst'] == '@all')
+ return true;
+ else if (strncmp($options['filter_pinst'], '@merge_', 7) == 0)
+ return true;
+ else if ($options['filter_pinst'] == $pinst)
+ return true;
+ else
+ return false;
+ } else
+ return true;
+}
+
+function _collectd_list_cb_type(&$options, $host, $plugin, $pinst, $type) {
+ if ($options['cb_tinst'] === false) {
+ $options['result'][] = $type;
+ return false;
+ } else if (isset($options['filter_type'])) {
+ if ($options['filter_type'] == '@all')
+ return true;
+ else if ($options['filter_type'] == $type)
+ return true;
+ else
+ return false;
+ } else
+ return true;
+}
+
+function _collectd_list_cb_tinst(&$options, $host, $plugin, $pinst, $type, $tinst) {
+ $options['result'][] = $tinst;
+ return false;
+}
+
+function _collectd_list_cb_graph(&$options, $host, $plugin, $pinst, $type, $tinst) {
+ if (isset($options['filter_tinst'])) {
+ if ($options['filter_tinst'] == '@all') {
+ } else if ($options['filter_tinst'] == $tinst) {
+ } else if (strncmp($options['filter_tinst'], '@merge', 6) == 0) {
+ // Need to exclude @merge with non-existent meta graph
+ } else
+ return false;
+ }
+ if (isset($options['filter_pinst']) && strncmp($options['filter_pinst'], '@merge', 6) == 0)
+ $pinst = $options['filter_pinst'];
+ if (isset($options['filter_tinst']) && strncmp($options['filter_tinst'], '@merge', 6) == 0)
+ $tinst = $options['filter_tinst'];
+ $ident = collectd_identifier($host, $plugin, $pinst, $type, $tinst);
+ if (!in_array($ident, $options['ridentifiers'])) {
+ $options['ridentifiers'][] = $ident;
+ $options['result'][] = array('host'=>$host, 'plugin'=>$plugin, 'pinst'=>$pinst, 'type'=>$type, 'tinst'=>$tinst);
+ }
+}
+
+/**
+ * Fetch list of hosts found in collectd's datadirs.
+ * @return Sorted list of hosts (sorted by label from rigth to left)
+ */
+function collectd_list_hosts() {
+ $options = array(
+ 'result' => array(),
+ 'cb_host' => '_collectd_list_cb_host',
+ 'cb_plugin' => false,
+ 'cb_pinst' => false,
+ 'cb_type' => false,
+ 'cb_tinst' => false
+ );
+ collectd_walk($options);
+ $hosts = array_unique($options['result']);