
本镜像基于官方Telegraf Docker镜像构建,扩展集成了Python3环境和pysnmp4模块。主要用途是允许在Telegraf容器内直接运行Python3脚本,并通过pysnmp4实现与其他设备的SNMP协议通信,适用于需要通过Python处理SNMP数据的监控场景。
更多关于基础Telegraf镜像的信息可参考https://registry.hub.docker.com/_/telegraf/%E3%80%82
bashdocker pull [镜像名称] # 请替换为实际镜像名称
bashdocker run -d \ --name telegraf-python-snmp \ -v /path/to/telegraf.conf:/etc/telegraf/telegraf.conf \ -v /path/to/python/scripts:/scripts \ [镜像名称]
telegraf.conf,配置示例(通过exec插件运行Python脚本):toml[[inputs.exec]] commands = ["python3 /scripts/snmp_collector.py"] interval = "10s" timeout = "5s" data_format = "influx"
Python脚本放置:将SNMP采集脚本(如snmp_collector.py)挂载到容器内指定路径(如/scripts)
SNMP脚本示例:使用pysnmp4的基础SNMP采集脚本
pythonfrom pysnmp.hlapi import * def snmp_get(): errorIndication, errorStatus, errorIndex, varBinds = next( getCmd(SnmpEngine(), CommunityData('public', mpModel=0), UdpTransportTarget(('192.168.1.1', 161)), ContextData(), ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))) # 系统描述OID ) if errorIndication: print(errorIndication) elif errorStatus: print('%s at %s' % (errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex)-1][0] or '?')) else: for varBind in varBinds: print(' = '.join([x.prettyPrint() for x in varBind])) if __name__ == "__main__": snmp_get()
yamlversion: '3' services: telegraf: image: [镜像名称] container_name: telegraf-python-snmp volumes: - ./telegraf.conf:/etc/telegraf/telegraf.conf - ./scripts:/scripts restart: always network_mode: host # 如需访问本地网络设备,建议使用host网络模式

探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
manifest unknown
no matching manifest(架构)
invalid tar header(解压)
TLS 证书失败
DNS 超时
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务