228 lines
4.8 KiB
Go
228 lines
4.8 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"git.loafle.net/overflow/ssh_crawler/crawler"
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
config "git.loafle.net/overflow/overflow_commons_go/modules/config/model"
|
|
"log"
|
|
"git.loafle.net/overflow/ssh_crawler/stat"
|
|
)
|
|
|
|
func main() {
|
|
cc := config.Config{}
|
|
|
|
|
|
data, err := ioutil.ReadFile("./config/test.json")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
err = json.Unmarshal(data, &cc)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
start(&cc)
|
|
}
|
|
|
|
func start(c *config.Config) {
|
|
|
|
ip := c.Target.Connection.Ip
|
|
port := c.Target.Connection.Port
|
|
user := c.Target.Auth["id"].(string)
|
|
pw := c.Target.Auth["pw"].(string)
|
|
keyFilePathObj := c.Target.Auth["keyFilePath"]
|
|
var keyFilePath string = ""
|
|
if keyFilePathObj != nil {
|
|
keyFilePath = keyFilePathObj.(string)
|
|
}
|
|
|
|
|
|
cr, err := crawler.New(ip, port, user, pw, keyFilePath)
|
|
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
|
|
var inter crawler.SSHCrawlerModuler
|
|
for _, item := range c.Items {
|
|
mode := item.QueryInfo.Extend["mode"].(string)
|
|
|
|
switch mode {
|
|
case "cpu" :
|
|
inter = stat.CPUStat{}
|
|
break
|
|
case "mem" :
|
|
inter = stat.MemStat{}
|
|
break
|
|
default :
|
|
continue
|
|
}
|
|
|
|
ch := make(chan interface{})
|
|
cr.Process(inter, ch, item)
|
|
print(<-ch)
|
|
|
|
}
|
|
}
|
|
|
|
func main11() {
|
|
|
|
//const ip = "192.168.1.215"
|
|
//const port = "22"
|
|
//const user = "snoop"
|
|
//const pw = "qwe123"
|
|
//const keyFilePath = "" // /home/insanity/.ssh/id_rsa
|
|
//
|
|
//cr, err := crawler.New(ip, port, user, pw, keyFilePath)
|
|
//if err != nil {
|
|
// fmt.Println(err)
|
|
//}
|
|
//
|
|
//cpukeys := []string{
|
|
// "cpu.usage.sum",
|
|
// "cpu.usage.user",
|
|
// "cpu.usage.system",
|
|
// "cpu.usage.nice",
|
|
// "cpu.usage.idle",
|
|
// "cpu.usage.iowait",
|
|
// "cpu.usage.irq",
|
|
// "cpu.usage.softirq",
|
|
// "cpu.usage.steal",
|
|
// "cpu.usage.guest",
|
|
// "cpu.usage.gnice",
|
|
//}
|
|
//cpuCh := make(chan interface{})
|
|
//cr.CPUStat(cpuCh, cpukeys)
|
|
//print(<-cpuCh)
|
|
|
|
////Memory
|
|
//memkeys := []string {
|
|
// "mem.usage.total",
|
|
// "mem.usage.free",
|
|
// "mem.usage.available",
|
|
// "mem.usage.buffers",
|
|
// "mem.usage.cached",
|
|
// "mem.swap.usage.total",
|
|
// "mem.swap.usage.free",
|
|
// "mem.swap.usage.cached",
|
|
//}
|
|
//memCh := make(chan interface{})
|
|
//cr.MemStat(memCh, memkeys)
|
|
//print(<-memCh)
|
|
//
|
|
//
|
|
////Disk IO
|
|
//ioKeys := []string {
|
|
// "disk[0].io.device",
|
|
// "disk[0].io.readcnt",
|
|
// "disk[0].io.merged_readcnt",
|
|
// "disk[0].io.readbytes",
|
|
// "disk[0].io.readtime",
|
|
// "disk[0].io.writecnt",
|
|
// "disk[0].io.merged_writecnt",
|
|
// "disk[0].io.writebytes",
|
|
// "disk[0].io.writetime",
|
|
// "disk[0].io.iotime",
|
|
// "disk[0].io.weighted",
|
|
//
|
|
// "disk[1].io.readcnt",
|
|
// "disk[1].io.merged_readcnt",
|
|
// "disk[1].io.readbytes",
|
|
// "disk[1].io.readtime",
|
|
//}
|
|
//diskioCh := make(chan interface{})
|
|
//cr.DiskIOStat(diskioCh, ioKeys)
|
|
//print(<-diskioCh)
|
|
//
|
|
//
|
|
////Disk Free
|
|
//diskFreekeys := []string {
|
|
// "disk[0].usage.fs",
|
|
// "disk[0].usage.used",
|
|
// "disk[0].usage.available",
|
|
// "disk[0].usage.usedperc",
|
|
// "disk[0].usage.mounted",
|
|
//
|
|
// "disk[1].usage.fs",
|
|
// "disk[2].usage.fs",
|
|
//}
|
|
//diskFreeCh := make(chan interface{})
|
|
//cr.DiskFreeStat(diskFreeCh, diskFreekeys)
|
|
//print(<-diskFreeCh)
|
|
//
|
|
//
|
|
////Disk Inode Free
|
|
//diskInodeKeys := []string {
|
|
// "disk[0].inode.usage.fs",
|
|
// "disk[0].inode.usage.used",
|
|
// "disk[0].inode.usage.available",
|
|
// "disk[0].inode.usage.usedperc",
|
|
// "disk[0].inode.usage.mounted",
|
|
//
|
|
// "disk[1].inode.usage.fs",
|
|
// "disk[2].inode.usage.fs",
|
|
//}
|
|
//diskInodeFreeCh := make(chan interface{})
|
|
//cr.DiskIFreeStat(diskInodeFreeCh, diskInodeKeys)
|
|
//print(<-diskInodeFreeCh)
|
|
//
|
|
//
|
|
//
|
|
////Network
|
|
//netKeys := []string {
|
|
// "net[0].transfer.iface",
|
|
// "net[0].transfer.recv_byte",
|
|
// "net[0].transfer.recv_packet",
|
|
// "net[0].transfer.recv_err",
|
|
// "net[0].transfer.recv_drop",
|
|
// "net[0].transfer.recv_fifo",
|
|
// "net[0].transfer.recv_frame",
|
|
// "net[0].transfer.recv_compressed",
|
|
// "net[0].transfer.recv_multicast",
|
|
// "net[0].transfer.send_byte",
|
|
// "net[0].transfer.send_packet",
|
|
// "net[0].transfer.send_err",
|
|
// "net[0].transfer.send_drop",
|
|
// "net[0].transfer.send_fifo",
|
|
// "net[0].transfer.send_frame",
|
|
// "net[0].transfer.send_compressed",
|
|
// "net[0].transfer.send_multicast",
|
|
//
|
|
// "net[1].transfer.recv_packet",
|
|
// "net[1].transfer.send_compressed",
|
|
// "net[1].transfer.send_packet",
|
|
//}
|
|
//netCh := make(chan interface{})
|
|
//cr.NetworkStat(netCh, netKeys)
|
|
//print(<-netCh)
|
|
//
|
|
//
|
|
////Load Avg.
|
|
//loadCh := make(chan interface{})
|
|
//cr.LoadAvgStat(loadCh)
|
|
//print(<-loadCh)
|
|
//
|
|
////Uptime
|
|
//uptCh := make(chan interface{})
|
|
//cr.Uptime(uptCh)
|
|
//print(<-uptCh)
|
|
//
|
|
////Process (It doesn't to be a Map. will be displayed by a list)
|
|
//psCh := make(chan interface{})
|
|
//cr.ProcessStat(psCh)
|
|
//print(<-psCh)
|
|
}
|
|
|
|
func print(data interface{}) {
|
|
jsonData, err := json.Marshal(data)
|
|
if err != nil {
|
|
fmt.Errorf("%s\n", err)
|
|
}
|
|
|
|
fmt.Println(string(jsonData))
|
|
}
|
|
|