Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
cf0288a11c | |||
fa9c16f410 | |||
18dcafd440 | |||
6641d00247 | |||
beaf18eb8e | |||
5c4a1272c1 | |||
c110403a0d | |||
b913d49317 | |||
8b23731451 | |||
86723f24ca | |||
a52fb3c43d | |||
ef2dd31219 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
nmdc-log-service
|
80
README.md
Normal file
80
README.md
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
# nmdc-log-service
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
A logging service for NMDC hubs.
|
||||||
|
|
||||||
|
It logs public chat messages to a file, categorised by months. Binaries are provided for Windows/Linux amd64/i386.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```
|
||||||
|
$nmdc-log-service -Help
|
||||||
|
|
||||||
|
Usage of nmdc-log-service:
|
||||||
|
-Debug
|
||||||
|
Print additional information on stdout
|
||||||
|
-Dir string
|
||||||
|
Output directory (default ".")
|
||||||
|
-LogConnectionState
|
||||||
|
Include connection state changes in log (default true)
|
||||||
|
-Nick string
|
||||||
|
Nick (default "nmdc-log-service")
|
||||||
|
-PMResponse string
|
||||||
|
Message to respond with on PM (default "This is an automated service. For enquiries, please contact an administrator.")
|
||||||
|
-Password string
|
||||||
|
Registered nick password
|
||||||
|
-Server string
|
||||||
|
Addresses to connect to (comma-separated)
|
||||||
|
-VerifyTLS
|
||||||
|
Verify TLS certificates (default true)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Changelog
|
||||||
|
|
||||||
|
master
|
||||||
|
- Convert to Go Modules, upgrade `libnmdc` to `v0.18.0`
|
||||||
|
|
||||||
|
2016-04-16 1.0.4
|
||||||
|
- Enhancement: Upgrade `libnmdc` from `r5` to `r6`
|
||||||
|
- Include a sample systemd unit script in source archive
|
||||||
|
- Fix an issue showing zero connected hubs in user tag
|
||||||
|
- Fix a cosmetic issue with logging repeated identical connection failure messages
|
||||||
|
- [⬇️ nmdc-log-service-1.0.4-win64.7z](dist-archive/nmdc-log-service-1.0.4-win64.7z) *(873.36 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.4-win32.7z](dist-archive/nmdc-log-service-1.0.4-win32.7z) *(804.14 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.4-src.7z](dist-archive/nmdc-log-service-1.0.4-src.7z) *(2.05 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.4-linux64.tar.xz](dist-archive/nmdc-log-service-1.0.4-linux64.tar.xz) *(965.75 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.4-linux32.tar.xz](dist-archive/nmdc-log-service-1.0.4-linux32.tar.xz) *(903.36 KiB)*
|
||||||
|
|
||||||
|
2016-04-04 1.0.3
|
||||||
|
- Enhancement: Upgrade `libnmdc` from `r4` to `r5`
|
||||||
|
- [⬇️ nmdc-log-service-1.0.3-win64.7z](dist-archive/nmdc-log-service-1.0.3-win64.7z) *(873.26 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.3-win32.7z](dist-archive/nmdc-log-service-1.0.3-win32.7z) *(803.45 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.3-linux64.tar.xz](dist-archive/nmdc-log-service-1.0.3-linux64.tar.xz) *(965.26 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.3-linux32.tar.xz](dist-archive/nmdc-log-service-1.0.3-linux32.tar.xz) *(902.95 KiB)*
|
||||||
|
|
||||||
|
2016-04-03 1.0.2
|
||||||
|
- Enhancement: Upgrade `libnmdc` from `r3` to `r4`
|
||||||
|
- [⬇️ nmdc-log-service-1.0.2-win64.7z](dist-archive/nmdc-log-service-1.0.2-win64.7z) *(872.64 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.2-win32.7z](dist-archive/nmdc-log-service-1.0.2-win32.7z) *(802.16 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.2-linux64.tar.xz](dist-archive/nmdc-log-service-1.0.2-linux64.tar.xz) *(965.06 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.2-linux32.tar.xz](dist-archive/nmdc-log-service-1.0.2-linux32.tar.xz) *(902.40 KiB)*
|
||||||
|
|
||||||
|
2016-04-03 1.0.1
|
||||||
|
- Enhancement: Add `-VerifyTLS` option
|
||||||
|
- Enhancement: Upgrade `libnmdc` from `r2` to `r3`
|
||||||
|
- Fix an issue writing log files on Linux
|
||||||
|
- Fix a cosmetic issue with error message formatting
|
||||||
|
- [⬇️ nmdc-log-service-1.0.1-win64.7z](dist-archive/nmdc-log-service-1.0.1-win64.7z) *(874.59 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.1-win32.7z](dist-archive/nmdc-log-service-1.0.1-win32.7z) *(802.05 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.1-src.7z](dist-archive/nmdc-log-service-1.0.1-src.7z) *(2.13 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.1-linux64.tar.xz](dist-archive/nmdc-log-service-1.0.1-linux64.tar.xz) *(965.03 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.1-linux32.tar.xz](dist-archive/nmdc-log-service-1.0.1-linux32.tar.xz) *(902.57 KiB)*
|
||||||
|
|
||||||
|
2016-04-02 1.0.0
|
||||||
|
- Initial public release
|
||||||
|
- [⬇️ nmdc-log-service-1.0.0-win64.7z](dist-archive/nmdc-log-service-1.0.0-win64.7z) *(872.66 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.0-win32.7z](dist-archive/nmdc-log-service-1.0.0-win32.7z) *(802.90 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.0-src.7z](dist-archive/nmdc-log-service-1.0.0-src.7z) *(2.05 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.0-linux64.tar.xz](dist-archive/nmdc-log-service-1.0.0-linux64.tar.xz) *(964.44 KiB)*
|
||||||
|
- [⬇️ nmdc-log-service-1.0.0-linux32.tar.xz](dist-archive/nmdc-log-service-1.0.0-linux32.tar.xz) *(902.47 KiB)*
|
@ -1,43 +0,0 @@
|
|||||||
A logging service for NMDC hubs.
|
|
||||||
|
|
||||||
It logs public chat messages to a file, categorised by months. Binaries are provided for Windows/Linux amd64/i386.
|
|
||||||
|
|
||||||
Written in golang
|
|
||||||
Tags: nmdc
|
|
||||||
|
|
||||||
=USAGE=
|
|
||||||
|
|
||||||
`$nmdc-log-service -Help
|
|
||||||
|
|
||||||
Usage of nmdc-log-service:
|
|
||||||
-Debug
|
|
||||||
Print additional information on stdout
|
|
||||||
-Dir string
|
|
||||||
Output directory (default ".")
|
|
||||||
-LogConnectionState
|
|
||||||
Include connection state changes in log (default true)
|
|
||||||
-Nick string
|
|
||||||
Nick (default "nmdc-log-service")
|
|
||||||
-PMResponse string
|
|
||||||
Message to respond with on PM (default "This is an automated service. For enquiries, please contact an administrator.")
|
|
||||||
-Password string
|
|
||||||
Registered nick password
|
|
||||||
-Server string
|
|
||||||
Addresses to connect to (comma-separated)
|
|
||||||
-VerifyTLS
|
|
||||||
Verify TLS certificates (default true)
|
|
||||||
`
|
|
||||||
|
|
||||||
=CHANGELOG=
|
|
||||||
|
|
||||||
2016-04-03 1.0.2
|
|
||||||
- Enhancement: Upgrade `libnmdc` from `r3` to `r4`
|
|
||||||
|
|
||||||
2016-04-03 1.0.1
|
|
||||||
- Enhancement: Add `-VerifyTLS` option
|
|
||||||
- Enhancement: Upgrade `libnmdc` from `r2` to `r3`
|
|
||||||
- Fix an issue writing log files on Linux
|
|
||||||
- Fix a cosmetic issue with error message formatting
|
|
||||||
|
|
||||||
2016-04-02 1.0.0
|
|
||||||
- Initial public release
|
|
11
build.sh
11
build.sh
@ -7,6 +7,13 @@ export GOPATH=$(
|
|||||||
cygpath -w "$(pwd)"
|
cygpath -w "$(pwd)"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
sanitise() {
|
||||||
|
local tmp=$(mktemp)
|
||||||
|
cat "$1" | perl -pe 's~C:.Users.......Documents.DEV.~C:/xxxxxxxxxxxxxxxxxxxxxxxxx/~g' > "$tmp"
|
||||||
|
mv "$tmp" "$1"
|
||||||
|
chmod 755 "$1"
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
|
||||||
local version=""
|
local version=""
|
||||||
@ -25,21 +32,25 @@ main() {
|
|||||||
|
|
||||||
echo "Building win64..."
|
echo "Building win64..."
|
||||||
GOARCH=amd64 GOOS=windows go build -a -ldflags -s -o nmdc-log-service.exe
|
GOARCH=amd64 GOOS=windows go build -a -ldflags -s -o nmdc-log-service.exe
|
||||||
|
sanitise nmdc-log-service.exe
|
||||||
7z a -mx9 nmdc-log-service-${version}-win64.7z nmdc-log-service.exe >/dev/null
|
7z a -mx9 nmdc-log-service-${version}-win64.7z nmdc-log-service.exe >/dev/null
|
||||||
rm ./nmdc-log-service.exe
|
rm ./nmdc-log-service.exe
|
||||||
|
|
||||||
echo "Building win32..."
|
echo "Building win32..."
|
||||||
GOARCH=386 GOOS=windows go build -a -ldflags -s -o nmdc-log-service.exe
|
GOARCH=386 GOOS=windows go build -a -ldflags -s -o nmdc-log-service.exe
|
||||||
|
sanitise nmdc-log-service.exe
|
||||||
7z a -mx9 nmdc-log-service-${version}-win32.7z nmdc-log-service.exe >/dev/null
|
7z a -mx9 nmdc-log-service-${version}-win32.7z nmdc-log-service.exe >/dev/null
|
||||||
rm ./nmdc-log-service.exe
|
rm ./nmdc-log-service.exe
|
||||||
|
|
||||||
echo "Building linux64..."
|
echo "Building linux64..."
|
||||||
GOARCH=amd64 GOOS=linux go build -a -ldflags -s -o nmdc-log-service
|
GOARCH=amd64 GOOS=linux go build -a -ldflags -s -o nmdc-log-service
|
||||||
|
sanitise nmdc-log-service
|
||||||
XZ_OPT=-9 tar caf nmdc-log-service-${version}-linux64.tar.xz nmdc-log-service --owner=0 --group=0
|
XZ_OPT=-9 tar caf nmdc-log-service-${version}-linux64.tar.xz nmdc-log-service --owner=0 --group=0
|
||||||
rm ./nmdc-log-service
|
rm ./nmdc-log-service
|
||||||
|
|
||||||
echo "Building linux32..."
|
echo "Building linux32..."
|
||||||
GOARCH=386 GOOS=linux go build -a -ldflags -s -o nmdc-log-service
|
GOARCH=386 GOOS=linux go build -a -ldflags -s -o nmdc-log-service
|
||||||
|
sanitise nmdc-log-service
|
||||||
XZ_OPT=-9 tar caf nmdc-log-service-${version}-linux32.tar.xz nmdc-log-service --owner=0 --group=0
|
XZ_OPT=-9 tar caf nmdc-log-service-${version}-linux32.tar.xz nmdc-log-service --owner=0 --group=0
|
||||||
rm ./nmdc-log-service
|
rm ./nmdc-log-service
|
||||||
|
|
||||||
|
BIN
dist-archive/nmdc-log-service-1.0.0-linux32.tar.xz
Normal file
BIN
dist-archive/nmdc-log-service-1.0.0-linux32.tar.xz
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.0-linux64.tar.xz
Normal file
BIN
dist-archive/nmdc-log-service-1.0.0-linux64.tar.xz
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.0-src.7z
Normal file
BIN
dist-archive/nmdc-log-service-1.0.0-src.7z
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.0-win32.7z
Normal file
BIN
dist-archive/nmdc-log-service-1.0.0-win32.7z
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.0-win64.7z
Normal file
BIN
dist-archive/nmdc-log-service-1.0.0-win64.7z
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.1-linux32.tar.xz
Normal file
BIN
dist-archive/nmdc-log-service-1.0.1-linux32.tar.xz
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.1-linux64.tar.xz
Normal file
BIN
dist-archive/nmdc-log-service-1.0.1-linux64.tar.xz
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.1-src.7z
Normal file
BIN
dist-archive/nmdc-log-service-1.0.1-src.7z
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.1-win32.7z
Normal file
BIN
dist-archive/nmdc-log-service-1.0.1-win32.7z
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.1-win64.7z
Normal file
BIN
dist-archive/nmdc-log-service-1.0.1-win64.7z
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.2-linux32.tar.xz
Normal file
BIN
dist-archive/nmdc-log-service-1.0.2-linux32.tar.xz
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.2-linux64.tar.xz
Normal file
BIN
dist-archive/nmdc-log-service-1.0.2-linux64.tar.xz
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.2-win32.7z
Normal file
BIN
dist-archive/nmdc-log-service-1.0.2-win32.7z
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.2-win64.7z
Normal file
BIN
dist-archive/nmdc-log-service-1.0.2-win64.7z
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.3-linux32.tar.xz
Normal file
BIN
dist-archive/nmdc-log-service-1.0.3-linux32.tar.xz
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.3-linux64.tar.xz
Normal file
BIN
dist-archive/nmdc-log-service-1.0.3-linux64.tar.xz
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.3-win32.7z
Normal file
BIN
dist-archive/nmdc-log-service-1.0.3-win32.7z
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.3-win64.7z
Normal file
BIN
dist-archive/nmdc-log-service-1.0.3-win64.7z
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.4-linux32.tar.xz
Normal file
BIN
dist-archive/nmdc-log-service-1.0.4-linux32.tar.xz
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.4-linux64.tar.xz
Normal file
BIN
dist-archive/nmdc-log-service-1.0.4-linux64.tar.xz
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.4-src.7z
Normal file
BIN
dist-archive/nmdc-log-service-1.0.4-src.7z
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.4-win32.7z
Normal file
BIN
dist-archive/nmdc-log-service-1.0.4-win32.7z
Normal file
Binary file not shown.
BIN
dist-archive/nmdc-log-service-1.0.4-win64.7z
Normal file
BIN
dist-archive/nmdc-log-service-1.0.4-win64.7z
Normal file
Binary file not shown.
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module code.ivysaur.me/nmdc-log-service
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
||||||
|
require code.ivysaur.me/libnmdc v0.18.0
|
6
go.sum
Normal file
6
go.sum
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
code.ivysaur.me/libnmdc v0.6.0 h1:I1PygqHyS3Er/u7ekYramMQ5Rw957ighnDl53Jzz2Cc=
|
||||||
|
code.ivysaur.me/libnmdc v0.6.0/go.mod h1:ZHCjIX/zm29hd2H8YtzOBHiSyowZNOHvgoMRjKbBLLg=
|
||||||
|
code.ivysaur.me/libnmdc v0.18.0 h1:BobB138EidAC3wE55CuTY7bZrFXtOy/zlssI8V1zXMk=
|
||||||
|
code.ivysaur.me/libnmdc v0.18.0/go.mod h1:5FjI0QxZEPeVTeg/e2MyJzJUwpmyE5CBAOIi7eqSxlg=
|
||||||
|
github.com/cxmcc/tiger v0.0.0-20170524142333-bde35e2713d7 h1:jBEtq1t2gpn2kEzvRlCUxvvrxl5aSWkXNPwe/hwvSNQ=
|
||||||
|
github.com/cxmcc/tiger v0.0.0-20170524142333-bde35e2713d7/go.mod h1:ruCYvt9rtYymAr4rNmfYJrl1dz8HSXUFP7cufqKOsDI=
|
14
hublog.service
Normal file
14
hublog.service
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=NMDC Log Service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Environment=TZ=Etc/UTC
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/home/hublog/nmdc-log-service -Dir /home/hublog/logs/ -Server ... -Nick ... -Password '...' -VerifyTLS=false
|
||||||
|
Restart=always
|
||||||
|
RestartSec=30s
|
||||||
|
User=hublog
|
||||||
|
Group=nogroup
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
32
main.go
32
main.go
@ -3,12 +3,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"libnmdc"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.ivysaur.me/libnmdc"
|
||||||
)
|
)
|
||||||
|
|
||||||
var BaseDir string = "."
|
var BaseDir string = "."
|
||||||
@ -51,18 +52,23 @@ func LogMessage(hub, message string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HubWorker(addr, nick, password string) {
|
type HubWorker struct {
|
||||||
|
LastConnectionStateMessage string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *HubWorker) MainLoop(addr, nick, password string) {
|
||||||
|
|
||||||
opts := libnmdc.HubConnectionOptions{
|
opts := libnmdc.HubConnectionOptions{
|
||||||
Address: libnmdc.HubAddress(addr),
|
Address: libnmdc.HubAddress(addr),
|
||||||
SkipVerifyTLS: !VerifyTLS,
|
SkipVerifyTLS: !VerifyTLS,
|
||||||
Self: libnmdc.UserInfo{Nick: nick},
|
Self: libnmdc.NewUserInfo(nick),
|
||||||
NickPassword: password,
|
NickPassword: password,
|
||||||
}
|
}
|
||||||
hub := opts.Connect()
|
|
||||||
|
|
||||||
for {
|
evChan := make(chan libnmdc.HubEvent, 1)
|
||||||
event := <-hub.OnEvent
|
hub := libnmdc.ConnectAsync(&opts, evChan)
|
||||||
|
|
||||||
|
for event := range evChan {
|
||||||
|
|
||||||
if DebugMode {
|
if DebugMode {
|
||||||
fmt.Printf("DEBUG: %s %v\n", addr, event)
|
fmt.Printf("DEBUG: %s %v\n", addr, event)
|
||||||
@ -71,11 +77,16 @@ func HubWorker(addr, nick, password string) {
|
|||||||
switch event.EventType {
|
switch event.EventType {
|
||||||
case libnmdc.EVENT_CONNECTION_STATE_CHANGED:
|
case libnmdc.EVENT_CONNECTION_STATE_CHANGED:
|
||||||
if LogConnectionState {
|
if LogConnectionState {
|
||||||
|
str := "* " + event.StateChange.String()
|
||||||
if len(event.Message) > 0 {
|
if len(event.Message) > 0 {
|
||||||
LogMessage(addr, "* "+event.StateChange.Format()+" ("+event.Message+")")
|
str += " (" + event.Message + ")"
|
||||||
} else {
|
|
||||||
LogMessage(addr, "* "+event.StateChange.Format())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prevent logging the same message repeatedly
|
||||||
|
if str != this.LastConnectionStateMessage {
|
||||||
|
LogMessage(addr, str)
|
||||||
|
}
|
||||||
|
this.LastConnectionStateMessage = str
|
||||||
}
|
}
|
||||||
|
|
||||||
case libnmdc.EVENT_PUBLIC:
|
case libnmdc.EVENT_PUBLIC:
|
||||||
@ -135,7 +146,8 @@ func main() {
|
|||||||
os.MkdirAll(GetDirectoryNameForHub(hubaddr), 0755)
|
os.MkdirAll(GetDirectoryNameForHub(hubaddr), 0755)
|
||||||
|
|
||||||
// Launch logger
|
// Launch logger
|
||||||
go HubWorker(hubaddr, *nick, *password)
|
hw := HubWorker{}
|
||||||
|
go hw.MainLoop(hubaddr, *nick, *password)
|
||||||
|
|
||||||
launch_ct++
|
launch_ct++
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user