Skip to content
This repository was archived by the owner on Mar 15, 2019. It is now read-only.

Commit 4f634d8

Browse files
committed
Merge exec_log branch.
-Add arbitrary command execution. -System command exec with block connected handler. Options cmdname and cmdargs. Substitution of %h for block hash and %n for block number. -Document arbitrary command execution in README.md. -Bump version to 0.0.3. -Add spydata folder to .gitignore. -Remove some things from TODO text file. -Add travis.yml -Display currently connected network. -Fix reporting wrong error in rare case. -More comments in main.go.
1 parent 7d0bb0a commit 4f634d8

File tree

8 files changed

+238
-79
lines changed

8 files changed

+238
-79
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dcrspy.conf
2929
logs
3030
.vscode
3131
data/*
32+
spydata/*
3233

3334
# IntelliJ IDEA
3435
.idea

.travis.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: go
2+
go:
3+
- 1.5.3
4+
- 1.6
5+
sudo: false
6+
before_install:
7+
- gotools=golang.org/x/tools
8+
install:
9+
- go get -d -t -v ./...
10+
- go get -v $gotools/cmd/cover
11+
- go get -v github.com/bradfitz/goimports
12+
- go get -v github.com/golang/lint/golint
13+
script:
14+
- export PATH=$PATH:$GOPATH/bin
15+
- go install ./...

README.md

+94-41
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# dcrspy
22

3+
[![Build Status](http://img.shields.io/travis/chappjc/dcrspy.svg)](https://travis-ci.org/chappjc/dcrspy)
4+
[![ISC License](http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
35
[![Gitter](https://badges.gitter.im/chappjc/dcrspy.svg)](https://gitter.im/chappjc/dcrspy?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
46

57
dcrspy is a program to continuously monitor and log changes in various data
@@ -19,6 +21,63 @@ wallet connection is available.
1921

2022
See [Data Details](#data-details) below for more information.
2123

24+
## Arbitrary Command Execution
25+
26+
When dcrspy receives a new block notification from dcrd, data collection and
27+
recording is triggered. In addition, any system command may be executed in
28+
response to the new block. The flags to specify the command and the arguments
29+
to be used are:
30+
31+
-c, --cmdname= Command name to run. Must be on %PATH%.
32+
-a, --cmdargs= Comma-separated list of arguments for command to run.
33+
34+
The command name must be an executable (binary or script) on your PATH, which
35+
is $PATH in *NIX, and %PATH% in Windows.
36+
37+
### Command Arguments
38+
39+
Any arguments must be specified with
40+
cmdargs as a comma-separated list of strings. For example:
41+
42+
-c ping -a "127.0.0.1,-n,8"
43+
44+
will execute the following on Linux:
45+
46+
/usr/bin/ping 127.0.0.1 -n 8
47+
48+
Specifying multiple arguments without commas, using spaces directly, is
49+
incorrect. For example, `-a "127.0.0.1 -n 8"` will not work.
50+
51+
Note that if your command line arguments need to start with a dash (`-`) it is
52+
necessary to use the config file. For example,
53+
54+
cmdname=ls
55+
cmdargs="-al"
56+
57+
### Block Hash and Height Substitution
58+
59+
The new block hash and height at the time of command execution may be included
60+
on the command line using %h and %n, which are substituted for block hash and
61+
number. For example,
62+
63+
cmdname=echo
64+
cmdargs="New best block hash: %h; height: %n"
65+
66+
results in the following log entries (date removed for brevity):
67+
68+
[INF] DCRD: Block height 36435 connected
69+
[INF] EXEC: New best block hash: 000000000000070f7a0593aee0728d6b3334c1e454da06efc0138008dc1b1cbd; height: 36435
70+
[INF] EXEC: Command execution complete (success).
71+
72+
Note that the above command used a semicolon since a comma would have indicated
73+
a second argument and been replaced with a space by echo.
74+
75+
### Command Logging
76+
77+
User-specified system command execution uses the logging subsystem tagged with
78+
EXEC in the logs. Both stdout and stderr for the executed command are sent to
79+
the dcrspy log. The end of command execution is also logged, as shown in the
80+
example above.
2281

2382
## Output
2483

@@ -114,53 +173,46 @@ Quick tips:
114173
* JSON to file system, with `-j, --save-jsonfile`.
115174
* To monitor only block data (no wallet connection), use `--nostakeinfo`.
116175

117-
The full list of command line switches is below.
176+
The full list of command line switches is below, with current directory
177+
replaced by `...`:
118178

119179
~~~ none
180+
$ ./dcrspy -h
120181
Usage:
121-
dcrspy.exe [OPTIONS]
182+
dcrspy [OPTIONS]
122183
123184
Application Options:
124-
/C, /configfile: Path to configuration file
125-
(...\dcrspy.conf)
126-
/V, /version Display version information and exit
127-
/testnet Use the test network (default mainnet)
128-
/simnet Use the simulation test network (default mainnet)
129-
/d, /debuglevel: Logging level {trace, debug, info, warn, error,
130-
critical} (info)
131-
/q, /quiet Easy way to set debuglevel to error
132-
/logdir: Directory to log output (...\logs)
133-
/e, /nomonitor Do not launch monitors. Display current data and
134-
(e)xit.
135-
/noblockdata Do not collect block data (default false)
136-
/nostakeinfo Do not collect stake info data (default false)
137-
/f, /outfolder: Folder for file outputs (...\spydata)
138-
/s, /summary Write plain text summary of key data to stdout
139-
/o, /save-jsonstdout Save JSON-formatted data to stdout
140-
/j, /save-jsonfile Save JSON-formatted data to file
141-
/dcrduser: Daemon RPC user name
142-
/dcrdpass: Daemon RPC password
143-
/dcrdserv: Hostname/IP and port of dcrd RPC server to connect to
144-
(default localhost:9109, testnet: localhost:19109,
145-
simnet: localhost:19556)
146-
/dcrdcert: File containing the dcrd certificate file
147-
(%localappdata%\Dcrd\rpc.cert)
148-
/dcrwuser: Wallet RPC user name
149-
/dcrwpass: Wallet RPC password
150-
/dcrwserv: Hostname/IP and port of dcrwallet RPC server to
151-
connect to (default localhost:9110, testnet:
152-
localhost:19110, simnet: localhost:19557)
153-
/dcrwcert: File containing the dcrwallet certificate file
154-
(%localappdata%\Dcrwallet\rpc.cert)
155-
/noclienttls Disable TLS for the RPC client -- NOTE: This is only
156-
allowed if the RPC client is connecting to localhost
157-
/accountname: Name of the account from (default: default) (default)
158-
/ticketaddress: Address to which you have given voting rights
159-
/pooladdress: Address to which you have given rights to pool fees
185+
-C, --configfile= Path to configuration file (.../dcrspy.conf)
186+
-V, --version Display version information and exit
187+
--testnet Use the test network (default mainnet)
188+
--simnet Use the simulation test network (default mainnet)
189+
-d, --debuglevel= Logging level {trace, debug, info, warn, error, critical} (info)
190+
-q, --quiet Easy way to set debuglevel to error
191+
--logdir= Directory to log output (.../logs)
192+
-c, --cmdname= Command name to run. Must be on %PATH%.
193+
-a, --cmdargs= Comma-separated list of aruguments for command to run.
194+
-e, --nomonitor Do not launch monitors. Display current data and (e)xit.
195+
--noblockdata Do not collect block data (default false)
196+
--nostakeinfo Do not collect stake info data (default false)
197+
-f, --outfolder= Folder for file outputs (.../spydata)
198+
-s, --summary Write plain text summary of key data to stdout
199+
-o, --save-jsonstdout Save JSON-formatted data to stdout
200+
-j, --save-jsonfile Save JSON-formatted data to file
201+
--dcrduser= Daemon RPC user name
202+
--dcrdpass= Daemon RPC password
203+
--dcrdserv= Hostname/IP and port of dcrd RPC server to connect to (default localhost:9109, testnet: localhost:19109, simnet: localhost:19556)
204+
--dcrdcert= File containing the dcrd certificate file (~/.dcrd/rpc.cert)
205+
--dcrwuser= Wallet RPC user name
206+
--dcrwpass= Wallet RPC password
207+
--dcrwserv= Hostname/IP and port of dcrwallet RPC server to connect to (default localhost:9110, testnet: localhost:19110, simnet: localhost:19557)
208+
--dcrwcert= File containing the dcrwallet certificate file (~/.dcrwallet/rpc.cert)
209+
--noclienttls Disable TLS for the RPC client -- NOTE: This is only allowed if the RPC client is connecting to localhost
210+
--accountname= Name of the account from (default: default) (default)
211+
--ticketaddress= Address to which you have given voting rights
212+
--pooladdress= Address to which you have given rights to pool fees
160213
161214
Help Options:
162-
/? Show this help message
163-
/h, /help Show this help message
215+
-h, --help Show this help message
164216
~~~
165217

166218
### Config file
@@ -176,12 +228,13 @@ debuglevel=debug
176228
; Default outfolder is a folder called "dcrspy" in the working directory.
177229
; Change this with the outfolder option:
178230
; Windows
179-
outfolder=%appdata%/dcrspy/spydata
231+
; outfolder=%appdata%/dcrspy/spydata
180232
; Linux
181233
; outfolder=$HOME/dcrspy/spydata
182234

183235
; Uncomment for testnet
184236
;testnet=1
237+
; But also remember ports below, or do not specify for network defaults.
185238

186239
dcrduser=duser
187240
dcrdpass=asdfExample

TODO

-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@ dcrspy TODO
22
====
33

44
Output
5-
JSON
6-
stdout
75
MySQL
86
Memory?
97

108
Input
119
Types of data
12-
Which outputs
1310
Monitor relevant tx
14-
User specified command to execute on event
1511

1612
.dcrspy folder for config file and log (vs. current dir)
1713

config.go

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ type config struct {
5858
Quiet bool `short:"q" long:"quiet" description:"Easy way to set debuglevel to error"`
5959
LogDir string `long:"logdir" description:"Directory to log output"`
6060

61+
// Comamnd execution
62+
CmdName string `short:"c" long:"cmdname" description:"Command name to run. Must be on %PATH%."`
63+
CmdArgs string `short:"a" long:"cmdargs" description:"Comma-separated list of arguments for command to run."`
64+
6165
// Data I/O
6266
NoMonitor bool `short:"e" long:"nomonitor" description:"Do not launch monitors. Display current data and (e)xit."`
6367
NoCollectBlockData bool `long:"noblockdata" description:"Do not collect block data (default false)"`
@@ -303,6 +307,9 @@ func loadConfig() (*config, error) {
303307
cfg.DcrwServ = defaultHost + ":" + activeNet.RPCServerPort
304308
}
305309

310+
// Put comma-separated comamnd line aguments into slice of strings
311+
//cfg.CmdArgs = strings.Split(cfg.CmdArgs[0], ",")
312+
306313
// Output folder
307314
cfg.OutFolder = cleanAndExpandPath(cfg.OutFolder)
308315
cfg.OutFolder = filepath.Join(cfg.OutFolder, activeNet.Name)

log.go

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var (
2222
daemonLog = btclog.Disabled
2323
walletLog = btclog.Disabled
2424
clientLog = btclog.Disabled
25+
execLog = btclog.Disabled
2526
)
2627

2728
// subsystemLoggers maps each subsystem identifier to its associated logger.
@@ -30,6 +31,7 @@ var subsystemLoggers = map[string]btclog.Logger{
3031
"DCRD": daemonLog,
3132
"DCRW": walletLog,
3233
"RPCC": clientLog,
34+
"EXEC": execLog,
3335
}
3436

3537
// logClosure is used to provide a closure over expensive logging operations
@@ -65,6 +67,8 @@ func useLogger(subsystemID string, logger btclog.Logger) {
6567
walletLog = logger
6668
case "RPCC":
6769
clientLog = logger
70+
case "EXEC":
71+
execLog = logger
6872
}
6973
}
7074

0 commit comments

Comments
 (0)