Telegraf extends AbstractComponent { protected static void writeConfig(TelegrafConfig telegrafConfig, Writer writer, String logFilePath) { VelocityContext context = new VelocityContext(); context.put("logFilePath", logFilePath); context.put("intervalSeconds", telegrafConfig.intervalSeconds()); context.put("cloudwatchPlugins", telegrafConfig.cloudWatch()); context.put("protocol", telegrafConfig.isHostedVespa() ? "https" : "http"); VelocityEngine velocityEngine = new VelocityEngine(); velocityEngine.init(); velocityEngine.evaluate(context, writer, "TelegrafConfigWriter", getTemplateReader()); uncheck(writer::close); } @Inject  Telegraf(TelegrafRegistry telegrafRegistry, TelegrafConfig telegrafConfig); @Override void deconstruct();  }
@Test public void test_writing_correct_telegraf_plugin_config() { TelegrafConfig telegrafConfig = new TelegrafConfig.Builder() .cloudWatch( new TelegrafConfig.CloudWatch.Builder() .accessKeyName("accessKey1") .namespace("namespace1") .secretKeyName("secretKey1") .region("us-east-1") .consumer("consumer1") ) .cloudWatch( new TelegrafConfig.CloudWatch.Builder() .namespace("namespace2") .profile("awsprofile") .region("us-east-2") .consumer("consumer2") ) .intervalSeconds(300) .isHostedVespa(true) .build(); StringWriter stringWriter = new StringWriter(); String logFilePath = "/path/to/logs/telegraf/telegraf.log"; Telegraf.writeConfig(telegrafConfig, stringWriter, logFilePath); String expectedConfig = TestUtil.getFileContents( "telegraf-config-with-two-cloudwatch-plugins.txt"); assertEquals(expectedConfig, stringWriter.toString()); }