Go Command Agent

编程入门 行业动态 更新时间:2024-10-09 14:26:29

Go <a href=https://www.elefans.com/category/jswz/34/1767259.html style=Command Agent"/>

Go Command Agent

很多时候大家需要去某个服务器上去执行一段命令或者上传/下载一个文件,这个命令还可能是时间比较久的,不想一直等在那里,特别是内网里面,不要复杂的认证,比如CICD里面,这时候大家可以使用这个command agent部署在server上,从而通过rest api来轻松的执行命令。

github:GodQ/go-rest-agent (github)

这个agent是使用Go编写的,提供了多种OS/CPU的版本,可以拿来即用。

部署命令: 

nohup ./agent_linux_amd64 5000 &

下面是这个agent的5个api:

Agent API Example

Post File

curl -L -XPOST '127.0.0.1:5000/api/v1/file' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-F 'target_path="/tmp/aaa.yaml"' \
-F 'file=@"/Users/GodQ/a.yaml"'

response:

{"message": "Upload file successfully"
}

Get File

curl -L '127.0.0.1:5000/api/v1/file?file_path=%2Ftmp%2Faaa.yaml' \
-H 'Content-Type: application/x-www-form-urlencoded'

response:

<file content>

Post Command Request Task

curl -L -XPOST '127.0.0.1:5000/api/v1/tasks' \
-H 'Content-Type: application/json' \
-d '{"command": "date; sleep 5; date","timeout_seconds": 6
}'

response:

{"task_id": 1,"command": "date; sleep 5; date","timeout_seconds": 6,"retry_count": 0,"extra": "","key": "","callback_url": "","status": "doing","return_code": 0,"error_msg": "","start_time": "0001-01-01T00:00:00Z","end_time": "0001-01-01T00:00:00Z","duration": 0,"log_redis_key": "","log_redis_url": "","thread_name": "","stdout": ""
}

List Tasks

curl -L '127.0.0.1:5000/api/v1/tasks'

response:

{"1": {"task_id": 1,"command": "date; sleep 5; date","timeout_seconds": 6,"retry_count": 0,"extra": "","key": "","callback_url": "","status": "done","return_code": 0,"error_msg": "","start_time": "2023-11-13T11:06:50.863401+08:00","end_time": "2023-11-13T11:06:55.971313+08:00","duration": 5,"log_redis_key": "","log_redis_url": "","thread_name": "","stdout": "Mon Nov 13 11:06:50 CST 2023\nMon Nov 13 11:06:55 CST 2023\n"}
}

Get Task by ID

curl -L '127.0.0.1:5000/api/v1/tasks?task_id=1'

response:

{"1": {"task_id": 1,"command": "date; sleep 5; date","timeout_seconds": 6,"retry_count": 0,"extra": "","key": "","callback_url": "","status": "done","return_code": 0,"error_msg": "","start_time": "2023-11-13T11:06:50.863401+08:00","end_time": "2023-11-13T11:06:55.971313+08:00","duration": 5,"log_redis_key": "","log_redis_url": "","thread_name": "","stdout": "Mon Nov 13 11:06:50 CST 2023\nMon Nov 13 11:06:55 CST 2023\n"}
}

更多推荐

Go Command Agent

本文发布于:2023-11-15 02:14:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1591932.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Command   Agent

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!