File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed
kotlin/fi/hsl/transitdata/dbmonitor Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change 11package fi.hsl.transitdata.dbmonitor
22
33import fi.hsl.transitdata.dbmonitor.config.ConfigParser
4+ import java.io.File
5+ import java.sql.Connection
6+ import java.sql.DriverManager
7+ import java.sql.SQLException
8+ import java.util.*
49
510fun main () {
611 val config = ConfigParser .createConfig()
7- MonitorService .start(config)
12+ MonitorService .start(config, createPubtransConnection())
13+ }
14+
15+ @Throws(Exception ::class )
16+ private fun createPubtransConnection (): Connection {
17+ // Default path is what works with Docker out-of-the-box. Override with a local file if needed
18+ val secretFilePath: String = System .getenv(" FILEPATH_CONNECTION_STRING" ) ? : " /run/secrets/pubtrans_community_conn_string"
19+ val connectionString = Scanner (File (secretFilePath))
20+ .useDelimiter(" \\ Z" ).next()
21+ if (connectionString.isEmpty()) {
22+ throw Exception (" Failed to find Pubtrans connection string, exiting application" )
23+ }
24+ return DriverManager .getConnection(connectionString)
825}
Original file line number Diff line number Diff line change @@ -18,9 +18,9 @@ object MonitorService{
1818 private val f = JsonFactory ()
1919 private val mapper: ObjectMapper = ObjectMapper (f).registerModule(KotlinModule ())
2020
21- fun start (config : Config )= runBlocking {
21+ fun start (config : Config , connection : Connection )= runBlocking {
2222 try {
23- DriverManager .getConnection(config.getString( " endpoint " )) .use {
23+ connection .use {
2424 config.getConfigList(" databases" ).forEach {
2525 endpointToCheck -> checkIfDbIfReachable(endpointToCheck.getString(" dblabel" ), endpointToCheck.getString(" dbname" ), it)
2626 }
Original file line number Diff line number Diff line change 11slackbridge = ${?SLACK_BRIDGE}
22errormessage = "Alert from db monitor:"
3- endpoint = ${?TRANSITDATA_PUBTRANS_CONN_STRING}
43databases = [
54 {
65 dblabel = "OMM DB"
You can’t perform that action at this time.
0 commit comments