Skip to content

Commit b99ef3c

Browse files
author
Gustav Lillesæter
committed
publish parsed json to rapid and add logging
1 parent 386daa5 commit b99ef3c

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

src/main/kotlin/no/nav/hjelpemidler/Application.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import no.nav.helse.rapids_rivers.KafkaConfig
1212
import no.nav.helse.rapids_rivers.RapidApplication
1313
import no.nav.helse.rapids_rivers.RapidsConnection
1414
import no.nav.hjelpemidler.configuration.Configuration
15+
import no.nav.hjelpemidler.metrics.SensuMetrics
1516
import no.nav.hjelpemidler.rivers.LoggRiver
1617
import java.net.InetAddress
1718
import java.time.LocalDateTime
@@ -65,11 +66,12 @@ fun main() {
6566
try {
6667
validJson = Klaxon().parse<Statusinfo>(rawJson)
6768
sikkerlogg.info("Parsing incoming json request successful: ${Klaxon().toJsonString(validJson)}")
69+
SensuMetrics().meldingFraOebs()
6870
} catch (e: Exception) {
6971
// Deal with invalid json in request
7072
sikkerlogg.info("Parsing incoming json request failed with exception (responding 4xx): $e")
7173
e.printStackTrace()
72-
74+
SensuMetrics().feilVedMeldingFraOebs()
7375
call.respond(HttpStatusCode.BadRequest, "bad request: json not valid")
7476
return@post
7577
}
@@ -80,7 +82,11 @@ fun main() {
8082
// Publish the received json to our rapid
8183
rapidApp!!.publish(
8284
UUID.randomUUID().toString(),
83-
"{\"@id\": \"$uid\", \"@event_name\": \"oebs-listener-testevent\", \"@opprettet\": \"$opprettet\", \"fnrBruker\": ${validJson?.accountNumber} \"data\": $rawJson}"
85+
"{\"@id\": \"$uid\", \"@event_name\": \"oebs-listener-testevent\", \"@opprettet\": \"$opprettet\", \"fnrBruker\": ${validJson?.accountNumber} \"data\": ${
86+
Klaxon().toJsonString(
87+
validJson
88+
)
89+
}}"
8490
)
8591

8692
call.respond(HttpStatusCode.OK, "ok")
@@ -115,7 +121,7 @@ data class Statusinfo(
115121
@Json(name = "OrdreNumber")
116122
val ordreNumber: Int,
117123
@Json(name = "LineNumber")
118-
val lineNUmber: Int,
124+
val lineNumber: Int,
119125
@Json(name = "Description")
120126
val description: String,
121127
@Json(name = "CategoryDescription")

src/main/kotlin/no/nav/hjelpemidler/metrics/SensuMetrics.kt

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package no.nav.hjelpemidler.metrics
22

33
import no.nav.hjelpemidler.configuration.Configuration
4+
import org.influxdb.dto.Point
45
import org.slf4j.LoggerFactory
56
import java.net.URI
67
import java.net.http.HttpClient
@@ -9,7 +10,6 @@ import java.net.http.HttpResponse
910
import java.time.Duration
1011
import java.util.*
1112
import java.util.concurrent.TimeUnit
12-
import org.influxdb.dto.Point
1313

1414
class SensuMetrics {
1515
private val log = LoggerFactory.getLogger(SensuMetrics::class.java)
@@ -29,12 +29,19 @@ class SensuMetrics {
2929
registerPoint(MELDING_TIL_RAPID_FEILET, mapOf("counter" to 1L), emptyMap())
3030
}
3131

32+
fun meldingFraOebs() {
33+
registerPoint(MELDING_FRA_OEBS, mapOf("counter" to 1L), emptyMap())
34+
}
35+
36+
fun feilVedMeldingFraOebs() {
37+
registerPoint(OEBS_MELDING_FEIL, mapOf("counter" to 1L), emptyMap())
38+
}
39+
3240
fun test() {
3341
println("writing to sensu")
3442
registerPoint("testing", mapOf("counter" to 1L), emptyMap())
3543
}
3644

37-
3845
private fun registerPoint(measurement: String, fields: Map<String, Any>, tags: Map<String, String>) {
3946
log.info("Posting point to Influx: measurment {} fields {} tags {} ", measurement, fields, tags)
4047
val point = Point.measurement(measurement)
@@ -66,12 +73,12 @@ class SensuMetrics {
6673

6774
private class SensuEvent(sensuName: String, output: String) {
6875
val json: String = "{" +
69-
"\"name\":\"" + sensuName + "\"," +
70-
"\"type\":\"metric\"," +
71-
"\"handlers\":[\"events_nano\"]," +
72-
"\"output\":\"" + output.replace("\\", "\\\\", true) + "\"," +
73-
"\"status\":0" +
74-
"}"
76+
"\"name\":\"" + sensuName + "\"," +
77+
"\"type\":\"metric\"," +
78+
"\"handlers\":[\"events_nano\"]," +
79+
"\"output\":\"" + output.replace("\\", "\\\\", true) + "\"," +
80+
"\"status\":0" +
81+
"}"
7582
}
7683

7784
companion object {
@@ -82,7 +89,9 @@ class SensuMetrics {
8289
)
8390

8491
private const val SOKNADER = "hm-oebs-listener"
85-
const val MELDING_TIL_RAPID_SUKSESS = "$SOKNADER.soknadmottatt.rapid.suksess"
86-
const val MELDING_TIL_RAPID_FEILET = "$SOKNADER.soknadmottatt.rapid.feilet"
92+
const val MELDING_TIL_RAPID_SUKSESS = "$SOKNADER.rapid.suksess"
93+
const val MELDING_TIL_RAPID_FEILET = "$SOKNADER.rapid.feilet"
94+
const val MELDING_FRA_OEBS = "$SOKNADER.oebs.melding"
95+
const val OEBS_MELDING_FEIL = "$SOKNADER.oebs.feil"
8796
}
88-
}
97+
}

0 commit comments

Comments
 (0)