#!/bin/bash

# This testcase will perform some simple tests to make sure that some
# of telegraf's output plugins are working correctly.

set -e
set -x
set -o pipefail

# Enable some output plugins.
cat >> /etc/telegraf/telegraf.conf << EOF
[[outputs.http]]
  url = "http://127.0.0.1:8080/"
EOF

systemctl restart telegraf.service
# Give telegraf some time to collect data
sleep 2

### Analyze the outputs

## Prometheus

prometheus_output=$(mktemp)
# Save the output of the command so that we can analyze it
curl -s http://127.0.0.1:9273/metrics | tee $prometheus_output
grep go_ $prometheus_output

## HTTP

http_output=$(mktemp)
netcat -w 20 -l 8080 | tee $http_output
grep diskio $http_output

exit 0
