Skip to content

Commit

Permalink
Merge pull request #425 from nonylene/psql-sslrootcert
Browse files Browse the repository at this point in the history
[check-postgresql] Add sslrootcert option
  • Loading branch information
ne-sachirou committed Nov 11, 2020
2 parents 58b0235 + 89dcb70 commit ad7910f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
20 changes: 11 additions & 9 deletions check-postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,17 @@ command = ["check-postgresql", "connection", "--host", "127.0.0.1", "--port", "5
Checks the number of PostgreSQL connections.

```
-H, --host= Hostname (default: localhost)
-p, --port= Port (default: 5432)
-u, --user= Username (default: postgres)
-P, --password= Password [$PGPASSWORD]
-d, --database= DBname
-s, --sslmode= SSLmode (default: disable)
-t, --timeout= Maximum wait for connection, in seconds. (default: 5)
-w, --warning= warning if the number of connection is over (default: 70)
-c, --critical= critical if the number of connection is over (default: 90)
-H, --host= Hostname (default: localhost)
-p, --port= Port (default: 5432)
-u, --user= Username (default: postgres)
-P, --password= Password [$PGPASSWORD]
-d, --database= DBname
-s, --sslmode= SSLmode (default: disable)
--sslrootcert= The root certificate used for SSL certificate verification.
-t, --timeout= Maximum wait for connection, in seconds. (default: 5)
-w, --warning= warning if the number of connection is over (default: 70)
-c, --critical= critical if the number of connection is over (default: 90)
```

## For more information
Expand Down
18 changes: 11 additions & 7 deletions check-postgresql/lib/check-postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ var commands = map[string](func([]string) *checkers.Checker){
}

type postgresqlSetting struct {
Host string `short:"H" long:"host" default:"localhost" description:"Hostname"`
Port string `short:"p" long:"port" default:"5432" description:"Port"`
User string `short:"u" long:"user" default:"postgres" description:"Username"`
Password string `short:"P" long:"password" default:"" description:"Password" env:"PGPASSWORD"`
Database string `short:"d" long:"database" description:"DBname"`
SSLmode string `short:"s" long:"sslmode" default:"disable" description:"SSLmode"`
Timeout int `short:"t" long:"timeout" default:"5" description:"Maximum wait for connection, in seconds."`
Host string `short:"H" long:"host" default:"localhost" description:"Hostname"`
Port string `short:"p" long:"port" default:"5432" description:"Port"`
User string `short:"u" long:"user" default:"postgres" description:"Username"`
Password string `short:"P" long:"password" default:"" description:"Password" env:"PGPASSWORD"`
Database string `short:"d" long:"database" description:"DBname"`
SSLmode string `short:"s" long:"sslmode" default:"disable" description:"SSLmode"`
SSLRootCert string `long:"sslrootcert" description:"The root certificate used for SSL certificate verification."`
Timeout int `short:"t" long:"timeout" default:"5" description:"Maximum wait for connection, in seconds."`
}

func (p postgresqlSetting) getDriverAndDataSourceName() (string, string) {
Expand All @@ -30,6 +31,9 @@ func (p postgresqlSetting) getDriverAndDataSourceName() (string, string) {
dbName = p.Database
}
dataSourceName := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=%s connect_timeout=%d", p.User, p.Password, p.Host, p.Port, dbName, p.SSLmode, p.Timeout)
if p.SSLRootCert != "" {
dataSourceName += fmt.Sprintf(" sslrootcert=%s", p.SSLRootCert)
}
return "postgres", dataSourceName
}

Expand Down

0 comments on commit ad7910f

Please sign in to comment.