ssh_crawler/bootstrap/main.go

208 lines
4.2 KiB
Go
Raw Normal View History

2017-10-20 06:10:30 +00:00
package main
import (
"fmt"
2017-11-10 08:33:29 +00:00
2017-10-24 09:23:56 +00:00
"encoding/json"
2017-11-09 09:04:07 +00:00
"io/ioutil"
config "git.loafle.net/overflow/overflow_commons_go/modules/config/model"
"log"
2017-11-10 08:33:29 +00:00
"git.loafle.net/overflow/ssh_crawler"
2017-10-20 06:10:30 +00:00
)
func main() {
2017-11-09 09:04:07 +00:00
cc := config.Config{}
2017-10-20 06:10:30 +00:00
2017-11-09 09:04:07 +00:00
data, err := ioutil.ReadFile("./config/test.json")
2017-11-10 08:33:29 +00:00
2017-10-20 06:10:30 +00:00
if err != nil {
2017-11-09 09:04:07 +00:00
log.Fatal(err)
2017-10-20 06:10:30 +00:00
}
2017-11-09 09:04:07 +00:00
err = json.Unmarshal(data, &cc)
if err != nil {
log.Fatal(err)
2017-10-24 09:23:56 +00:00
}
2017-11-10 08:33:29 +00:00
ssc := ssh_crawler.NewSSHCrawler()
2017-10-24 09:23:56 +00:00
2017-11-10 08:33:29 +00:00
bb, err := ssc.Internal(cc)
if err != nil {
log.Fatal(err)
2017-10-24 09:23:56 +00:00
}
2017-11-10 08:33:29 +00:00
var m map[string]string
2017-10-24 09:23:56 +00:00
2017-11-10 08:33:29 +00:00
err = json.Unmarshal(bb, &m)
2017-10-26 02:38:04 +00:00
2017-11-09 09:04:07 +00:00
if err != nil {
2017-11-10 08:33:29 +00:00
log.Fatal(err)
2017-10-24 09:23:56 +00:00
}
2017-11-10 08:33:29 +00:00
log.Println(m)
2017-11-09 09:04:07 +00:00
}
2017-10-24 09:23:56 +00:00
2017-11-10 08:33:29 +00:00
2017-11-09 09:04:07 +00:00
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)
2017-10-24 09:23:56 +00:00
}
func print(data interface{}) {
jsonData, err := json.Marshal(data)
if err != nil {
2017-11-08 02:43:25 +00:00
fmt.Errorf("%s\n", err)
2017-10-24 09:23:56 +00:00
}
2017-11-08 02:43:25 +00:00
2017-10-24 09:23:56 +00:00
fmt.Println(string(jsonData))
2017-10-23 09:08:19 +00:00
}
2017-10-25 08:37:32 +00:00