Compare commits
No commits in common. "master" and "v1.0.1" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +0,0 @@
|
|||||||
nmdc-log-service
|
|
80
README.md
80
README.md
@ -1,80 +0,0 @@
|
|||||||
# 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)*
|
|
31
__dist/README.txt
Normal file
31
__dist/README.txt
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
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)`
|
||||||
|
|
||||||
|
=CHANGELOG=
|
||||||
|
|
||||||
|
2016-04-02 1.0.0
|
||||||
|
- Initial public release
|
11
build.sh
11
build.sh
@ -7,13 +7,6 @@ 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=""
|
||||||
@ -32,25 +25,21 @@ 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
|
||||||
|
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5
go.mod
5
go.mod
@ -1,5 +0,0 @@
|
|||||||
module code.ivysaur.me/nmdc-log-service
|
|
||||||
|
|
||||||
go 1.13
|
|
||||||
|
|
||||||
require code.ivysaur.me/libnmdc v0.18.0
|
|
6
go.sum
6
go.sum
@ -1,6 +0,0 @@
|
|||||||
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=
|
|
@ -1,14 +0,0 @@
|
|||||||
[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,13 +3,12 @@ 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 = "."
|
||||||
@ -52,23 +51,18 @@ func LogMessage(hub, message string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type HubWorker struct {
|
func HubWorker(addr, nick, password string) {
|
||||||
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.NewUserInfo(nick),
|
Self: libnmdc.UserInfo{Nick: nick},
|
||||||
NickPassword: password,
|
NickPassword: password,
|
||||||
}
|
}
|
||||||
|
hub := opts.Connect()
|
||||||
|
|
||||||
evChan := make(chan libnmdc.HubEvent, 1)
|
for {
|
||||||
hub := libnmdc.ConnectAsync(&opts, evChan)
|
event := <-hub.OnEvent
|
||||||
|
|
||||||
for event := range evChan {
|
|
||||||
|
|
||||||
if DebugMode {
|
if DebugMode {
|
||||||
fmt.Printf("DEBUG: %s %v\n", addr, event)
|
fmt.Printf("DEBUG: %s %v\n", addr, event)
|
||||||
@ -77,16 +71,11 @@ func (this *HubWorker) MainLoop(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 {
|
||||||
str += " (" + event.Message + ")"
|
LogMessage(addr, "* "+event.StateChange.Format()+" ("+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:
|
||||||
@ -146,8 +135,7 @@ func main() {
|
|||||||
os.MkdirAll(GetDirectoryNameForHub(hubaddr), 0755)
|
os.MkdirAll(GetDirectoryNameForHub(hubaddr), 0755)
|
||||||
|
|
||||||
// Launch logger
|
// Launch logger
|
||||||
hw := HubWorker{}
|
go HubWorker(hubaddr, *nick, *password)
|
||||||
go hw.MainLoop(hubaddr, *nick, *password)
|
|
||||||
|
|
||||||
launch_ct++
|
launch_ct++
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user