Skip to content

Commit

Permalink
custom config and updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Nithin Meppurathu committed Aug 11, 2016
1 parent c7297cc commit 995ac57
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .rtail.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
alliases:
error_log: /var/log/httpd/error_log
commands:
varnish: varnishlog
49 changes: 38 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,49 @@
#Rtail
Remote tail logging
Rtail
===============================
Remote multiplex server tailing & command execution runner

## OSX Install with Homebrew
## Install

### OSX Install with Homebrew

brew install https://raw.githubusercontent.com/chonthu/rtail/master/rtail.rb

## Use it just as you would regular tail locally
### From source

go get github.com/chonthu/rtail
go install

## Usage

### Use it just as you would regular tail locally
rtail will stream the log down locally from the remote client, by default the command your running is tail -f

rtail ec2-user@webserver1.myserver.com:/var/log/httpd/error_log

rtail -f ec2-user@webserver1.myserver.com:/var/log/httpd/error_log
You can run any command you want by using a '%' istead of ':' in the rtail parameter

## Follow tag works
rtail will stream the log down locally from the remote client
rtail "ec2-user@webserver1.myserver.com%cat /var/log/mail.log"

## Works with multiple servers!
### Works with multiple servers!
Pass as many server as you would like

rtail -f ec2-user@webserver1.myserver.com:/var/log/httpd/error_log johndoe@webserver2.myserver.com:/var/log/httpd/access_log
rtail ec2-user@webserver1.myserver.com:/var/log/httpd/error_log johndoe@webserver2.myserver.com:/var/log/httpd/access_log

### Allows custom range selector

rtail "root@webserver[1-5].myserver.com:/var/log/httpd/error_log"

### Custom alliases & commands
create a rtail.yml fil ein your working directory or in your home folder

---
alliases:
error_log: /var/log/httpd/error_log

commands:
varnish: varnishlog

## Allows custom range selector
Now you can run these custom command like so:

rtail -f root@webserver[1-5].myserver.com:/var/log/httpd/error_log
rtail myserver.web1:error_log
rtail myserver.web2%varnish
52 changes: 51 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package main

import (
"fmt"
"io/ioutil"
"math/rand"
"os"
"regexp"
"strconv"
"strings"
"sync"

"gopkg.in/yaml.v2"

"github.com/chonthu/ssh"
"github.com/fatih/color"
)
Expand All @@ -21,10 +24,46 @@ var (
color.New(color.FgBlue).SprintFunc(),
color.New(color.FgMagenta).SprintFunc(),
}

CONFIG_PATH = []string{
".rtail.yml",
"~/.rtail.yml",
}
)

var config = new(Config)

type Config struct {
Alliases map[string]string
Commands map[string]string
}

func initConfig(file *os.File) {
b, err := ioutil.ReadAll(file)
if err != nil {
fmt.Println("Invalid syntax in config file")
os.Exit(1)
}

err = yaml.Unmarshal(b, &config)
if err != nil {
fmt.Println("Invalid syntax in config file")
os.Exit(1)
}
}

func main() {

// Check if config is passed
for _, v := range CONFIG_PATH {
file, err := os.Open(v) // For read access.
if err == nil {
initConfig(file)
}
}

fmt.Println(config)

servers := parseServers(os.Args[1:])

if len(servers) < 1 {
Expand Down Expand Up @@ -100,6 +139,11 @@ func logFileShorcodes(name string) string {
case "error_log":
return "/var/log/httpd/error_log"
default:

if _, ok := config.Alliases[name]; ok {
return config.Alliases[name]
}

return name
}
}
Expand All @@ -112,9 +156,14 @@ func execShorcodes(name string) string {
return "varnishlog -q \"VCL_call eq 'HIT'\" -d"
case "varnish_miss":
return "varnishlog -q \"VCL_call eq 'MISS'\" -d"
case "varnish_security":
return "varnishlog | grep security.vcl"
case "varnish":
return "varnishlog"
default:
if _, ok := config.Commands[name]; ok {
return config.Commands[name]
}
return name
}
}
Expand All @@ -129,7 +178,7 @@ func Connect(server string) {
}

fileToLog := "/var/log/httpd/error_log"
cmdString := fmt.Sprintf("tail %v", fileToLog)
cmdString := fmt.Sprintf("tail -f %v", fileToLog)
// Is filename passed?
if strings.Contains(server, "%") {
fileSplit := strings.Split(server, "%")
Expand All @@ -145,6 +194,7 @@ func Connect(server string) {
fileSplit := strings.Split(server, ":")
fileToLog = logFileShorcodes(fileSplit[1])
server = fileSplit[0]
cmdString = fmt.Sprintf("tail -f %v", fileToLog)
}

c := colors[rand.Intn(len(colors))]
Expand Down

0 comments on commit 995ac57

Please # to comment.