本文整理汇总了Golang中mig/ninja/mig/client.Client.GetAgent方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.GetAgent方法的具体用法?Golang Client.GetAgent怎么用?Golang Client.GetAgent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mig/ninja/mig/client.Client
的用法示例。
在下文中一共展示了Client.GetAgent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: agentReader
// agentReader retrieves an agent from the api
// and enters prompt mode to analyze it
func agentReader(input string, cli client.Client) (err error) {
defer func() {
if e := recover(); e != nil {
err = fmt.Errorf("agentReader() -> %v", e)
}
}()
inputArr := strings.Split(input, " ")
if len(inputArr) < 2 {
panic("wrong order format. must be 'agent <agentid>'")
}
agtid, err := strconv.ParseFloat(inputArr[1], 64)
if err != nil {
panic(err)
}
agt, err := cli.GetAgent(agtid)
if err != nil {
panic(err)
}
fmt.Println("Entering agent reader mode. Type \x1b[32;1mexit\x1b[0m or press \x1b[32;1mctrl+d\x1b[0m to leave. \x1b[32;1mhelp\x1b[0m may help.")
fmt.Printf("Agent %.0f named '%s'\n", agt.ID, agt.Name)
prompt := fmt.Sprintf("\x1b[34;1magent %d>\x1b[0m ", uint64(agtid)%1000)
for {
// completion
var symbols = []string{"details", "exit", "help", "json", "pretty", "r", "lastactions"}
readline.Completer = func(query, ctx string) []string {
var res []string
for _, sym := range symbols {
if strings.HasPrefix(sym, query) {
res = append(res, sym)
}
}
return res
}
input, err := readline.String(prompt)
if err == io.EOF {
break
}
if err != nil {
fmt.Println("error: ", err)
break
}
orders := strings.Split(input, " ")
switch orders[0] {
case "details":
agt, err = cli.GetAgent(agtid)
if err != nil {
panic(err)
}
jEnv, err := json.MarshalIndent(agt.Env, "", " ")
if err != nil {
panic(err)
}
jTags, err := json.MarshalIndent(agt.Tags, "", " ")
if err != nil {
panic(err)
}
fmt.Printf(`Agent ID %.0f
name %s
last seen %s ago
version %s
mode %s
location %s
platform %s %s
pid %d
starttime %s
status %s
environment %s
tags %s
`, agt.ID, agt.Name, time.Now().Sub(agt.HeartBeatTS).String(), agt.Version, agt.Mode, agt.QueueLoc,
agt.Env.OS, agt.Env.Arch, agt.PID, agt.StartTime, agt.Status, jEnv, jTags)
case "exit":
fmt.Printf("exit\n")
goto exit
case "help":
fmt.Printf(`The following orders are available:
details print the details of the agent
exit exit this mode
help show this help
json <pretty> show the json of the agent registration
r refresh the agent (get latest version from upstream)
lastactions <limit> print the last actions that ran on the agent. limit=10 by default.
`)
case "lastactions":
limit := 10
if len(orders) > 1 {
limit, err = strconv.Atoi(orders[1])
if err != nil {
panic(err)
}
}
err = printAgentLastCommands(agtid, limit, cli)
if err != nil {
panic(err)
}
case "json":
var agtjson []byte
//.........这里部分代码省略.........