2021-05-21 09:08:43 +00:00
|
|
|
package sysmon.server;
|
2021-05-04 12:23:34 +00:00
|
|
|
|
2021-05-17 13:05:35 +00:00
|
|
|
import org.apache.camel.Exchange;
|
2021-09-13 15:13:58 +00:00
|
|
|
import org.apache.camel.LoggingLevel;
|
2021-05-04 12:23:34 +00:00
|
|
|
import org.apache.camel.builder.RouteBuilder;
|
|
|
|
import org.apache.camel.model.rest.RestBindingMode;
|
2021-05-07 15:53:47 +00:00
|
|
|
import org.apache.camel.spi.Registry;
|
2021-09-17 09:53:57 +00:00
|
|
|
import sysmon.shared.ComboResult;
|
2021-05-11 13:37:23 +00:00
|
|
|
|
2021-05-07 15:53:47 +00:00
|
|
|
public class ServerRouteBuilder extends RouteBuilder {
|
2021-05-04 12:23:34 +00:00
|
|
|
|
|
|
|
@Override
|
2022-02-16 11:34:51 +00:00
|
|
|
public void configure() {
|
2021-05-04 15:54:47 +00:00
|
|
|
|
2021-06-29 12:02:01 +00:00
|
|
|
final Registry registry = getContext().getRegistry();
|
|
|
|
final String dbname = registry.lookupByNameAndType("dbname", String.class);
|
|
|
|
final Integer threads = registry.lookupByNameAndType("threads", Integer.class);
|
2021-05-07 15:53:47 +00:00
|
|
|
|
2021-06-16 08:20:17 +00:00
|
|
|
restConfiguration().component("netty-http")
|
2021-05-04 12:23:34 +00:00
|
|
|
.bindingMode(RestBindingMode.auto)
|
2021-05-11 13:37:23 +00:00
|
|
|
.host(registry.lookupByNameAndType("http.host", String.class))
|
|
|
|
.port(registry.lookupByNameAndType("http.port", Integer.class));
|
2021-05-04 12:23:34 +00:00
|
|
|
|
|
|
|
rest()
|
|
|
|
.post("/metrics")
|
|
|
|
.consumes("application/json")
|
|
|
|
.produces("text/html")
|
2021-09-17 09:53:57 +00:00
|
|
|
.type(ComboResult.class)
|
2021-05-04 12:23:34 +00:00
|
|
|
.route()
|
2021-09-17 09:53:57 +00:00
|
|
|
.doTry()
|
|
|
|
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(202))
|
|
|
|
.setHeader("Content-Type", constant("application/x-www-form-urlencoded"))
|
|
|
|
.to("seda:inbound?discardWhenFull=true")
|
2022-11-07 16:44:14 +00:00
|
|
|
.setBody(simple("OK, received."))
|
2021-09-17 09:53:57 +00:00
|
|
|
.doCatch(Exception.class)
|
2021-09-22 13:46:48 +00:00
|
|
|
.log(LoggingLevel.WARN, "Error: ${exception.message}.")
|
2021-09-17 09:53:57 +00:00
|
|
|
.end()
|
2021-05-04 12:23:34 +00:00
|
|
|
.endRest();
|
2021-05-04 15:54:47 +00:00
|
|
|
|
2021-06-29 12:02:01 +00:00
|
|
|
fromF("seda:inbound?concurrentConsumers=%s", threads)
|
2021-09-22 13:46:48 +00:00
|
|
|
.log("From ${header.hostname}: ${body}.")
|
2021-05-06 11:26:53 +00:00
|
|
|
.doTry()
|
2021-09-17 09:53:57 +00:00
|
|
|
.process(new ComboResultToPointProcessor(dbname))
|
2021-09-02 19:40:22 +00:00
|
|
|
.toF("influxdb://ref.myInfluxConnection?batch=true") //&retentionPolicy=autogen
|
2021-05-06 11:26:53 +00:00
|
|
|
.doCatch(Exception.class)
|
2021-09-22 13:46:48 +00:00
|
|
|
.log(LoggingLevel.WARN, "Error: ${exception.message}.")
|
2021-05-06 11:26:53 +00:00
|
|
|
.end();
|
|
|
|
|
2021-05-04 12:23:34 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 15:54:47 +00:00
|
|
|
|
2021-05-04 12:23:34 +00:00
|
|
|
}
|