Skip to content

Commit aad3dfc

Browse files
authored
Merge pull request #76 from NETWAYS/feature/add-mongo
Add collector for MongoDB
2 parents 10b3574 + f84269a commit aad3dfc

File tree

6 files changed

+187
-0
lines changed

6 files changed

+187
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ Module: `keepalived`
126126

127127
See [modules/keepalived/collector.go](modules/keepalived/collector.go)
128128

129+
### MongoDB
130+
131+
Module: `mongodb`
132+
133+
* MongoDB version
134+
* Package versions
135+
* Service status
136+
* Configuration from `/etc/mongod.conf`
137+
138+
See [modules/mongodb/collector.go](modules/mongodb/collector.go) for details.
139+
129140
### MySQL
130141

131142
Module: `mysql`

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/NETWAYS/support-collector/modules/icingaweb2"
1515
"github.com/NETWAYS/support-collector/modules/influxdb"
1616
"github.com/NETWAYS/support-collector/modules/keepalived"
17+
"github.com/NETWAYS/support-collector/modules/mongodb"
1718
"github.com/NETWAYS/support-collector/modules/mysql"
1819
"github.com/NETWAYS/support-collector/modules/postgresql"
1920
"github.com/NETWAYS/support-collector/modules/puppet"
@@ -58,6 +59,7 @@ var modules = map[string]func(*collection.Collection){
5859
"icinga-director": icingadirector.Collect,
5960
"corosync": corosync.Collect,
6061
"keepalived": keepalived.Collect,
62+
"mongodb": mongodb.Collect,
6163
"mysql": mysql.Collect,
6264
"influxdb": influxdb.Collect,
6365
"postgresql": postgresql.Collect,
@@ -78,6 +80,7 @@ var (
7880
"icingadb",
7981
"corosync",
8082
"keepalived",
83+
"mongodb",
8184
"mysql",
8285
"influxdb",
8386
"postgresql",

modules/mongodb/collector.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package mongodb
2+
3+
import (
4+
"github.com/NETWAYS/support-collector/pkg/collection"
5+
"github.com/NETWAYS/support-collector/pkg/obfuscate"
6+
"os"
7+
"path/filepath"
8+
)
9+
10+
const ModuleName = "mongodb"
11+
12+
var relevantPaths = []string{
13+
"/etc/mongod.conf",
14+
}
15+
16+
var possibleDaemons = []string{
17+
"/usr/lib/systemd/system/mongod.service",
18+
"/lib/systemd/system/mongod.service",
19+
}
20+
21+
var services = []string{
22+
"mongod",
23+
}
24+
25+
var files = []string{
26+
"/etc/mongod.conf",
27+
}
28+
29+
var commands = map[string][]string{
30+
"mongod-version.txt": {"mongod", "--version"},
31+
"mongo-version.txt": {"mongo", "--version"},
32+
}
33+
34+
var obfuscators = []*obfuscate.Obfuscator{
35+
obfuscate.NewFile(`(?i)(?:password).*\s*:\s*(.*)`, `conf`),
36+
}
37+
38+
func Detect() bool {
39+
for _, path := range relevantPaths {
40+
_, err := os.Stat(path)
41+
if err == nil {
42+
return true
43+
}
44+
}
45+
46+
return false
47+
}
48+
49+
func Collect(c *collection.Collection) {
50+
if !Detect() {
51+
c.Log.Info("Could not find mongodb")
52+
return
53+
}
54+
55+
c.Log.Info("Collecting mongodb information")
56+
57+
c.RegisterObfuscators(obfuscators...)
58+
59+
for _, file := range files {
60+
c.AddFiles(ModuleName, file)
61+
}
62+
63+
for _, file := range possibleDaemons {
64+
c.AddFilesIfFound(ModuleName, file)
65+
}
66+
67+
c.AddInstalledPackagesRaw(filepath.Join(ModuleName, "packages.txt"), "*mongo*")
68+
69+
for _, service := range services {
70+
c.AddServiceStatusRaw(filepath.Join(ModuleName, "service-"+service+".txt"), service)
71+
}
72+
73+
for name, cmd := range commands {
74+
c.AddCommandOutput(filepath.Join(ModuleName, name), cmd[0], cmd[1:]...)
75+
}
76+
}

modules/mongodb/collector_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package mongodb
2+
3+
import (
4+
"bytes"
5+
"github.com/NETWAYS/support-collector/pkg/collection"
6+
"github.com/NETWAYS/support-collector/pkg/obfuscate"
7+
"github.com/NETWAYS/support-collector/pkg/util"
8+
"testing"
9+
)
10+
11+
func TestCollect(t *testing.T) {
12+
c := collection.New(&bytes.Buffer{})
13+
14+
Collect(c)
15+
}
16+
17+
func TestObfuscators(t *testing.T) {
18+
util.AssertObfuscationExample(t, obfuscators, obfuscate.KindFile, "/etc/mongod.conf")
19+
20+
util.AssertAllObfuscatorsTested(t, obfuscators)
21+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#System Log
2+
3+
systemLog.path: /var/log/mongodb/mongod.log
4+
systemLog.destination: file
5+
systemLog.logAppend: true
6+
systemLog.quiet: false
7+
8+
#Process Management
9+
processManagement:
10+
pidFilePath: /var/run/mongodb/mongod.pid
11+
12+
#Storage
13+
storage.dbPath: /var/lib/mongodb
14+
storage.journal.enabled: true
15+
16+
#Security
17+
security.authorization: disabled
18+
security.example.fooPassword: <string>
19+
20+
#Net
21+
net:
22+
port: <int>
23+
bindIp: <string>
24+
bindIpAll: <boolean>
25+
maxIncomingConnections: <int>
26+
wireObjectCheck: <boolean>
27+
ipv6: <boolean>
28+
unixDomainSocket:
29+
enabled: <boolean>
30+
tls:
31+
certificateKeyFilePassword: <string>
32+
clusterPassword: <string>
33+
34+
#Replication
35+
36+
#Sharding
37+
38+
#Operation Profiling
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#System Log
2+
3+
systemLog.path: /var/log/mongodb/mongod.log
4+
systemLog.destination: file
5+
systemLog.logAppend: true
6+
systemLog.quiet: false
7+
8+
#Process Management
9+
processManagement:
10+
pidFilePath: /var/run/mongodb/mongod.pid
11+
12+
#Storage
13+
storage.dbPath: /var/lib/mongodb
14+
storage.journal.enabled: true
15+
16+
#Security
17+
security.authorization: disabled
18+
security.example.fooPassword: <HIDDEN>
19+
20+
#Net
21+
net:
22+
port: <int>
23+
bindIp: <string>
24+
bindIpAll: <boolean>
25+
maxIncomingConnections: <int>
26+
wireObjectCheck: <boolean>
27+
ipv6: <boolean>
28+
unixDomainSocket:
29+
enabled: <boolean>
30+
tls:
31+
certificateKeyFilePassword: <HIDDEN>
32+
clusterPassword: <HIDDEN>
33+
34+
#Replication
35+
36+
#Sharding
37+
38+
#Operation Profiling

0 commit comments

Comments
 (0)