zabbix-api

一、API官方文档

https://www.zabbix.com/documentation/4.0/zh/manual/api

https://www.zabbix.com/documentation/5.0/zh/manual/api

二、使用示例

1、获取zabbix token 

curl -s -X POST http://192.168.1.1/zabbix/api_jsonrpc.php -H 'Content-Type: application/json-rpc' -d '{
    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {
        "user": "Admin",
        "password": "zaAdmin!@#$2019"
    },
    "id": 1,
    "auth": null
}' | python -m json.tool 

返回用户身份验证令牌:

{
    "id": 1,
    "jsonrpc": "2.0",
    "result": "8ef873a332822d8acdf6b6f6e4fb2398"
}

2、使用api检索主机

curl -s -X POST http://192.168.1.1/zabbix/api_jsonrpc.php -H 'Content-Type: application/json-rpc' -d '{
	"jsonrpc": "2.0",
	"method": "host.get",
	"params": {
		"output": [
			"hostid",
			"host"
		],
		"selectInterfaces": [
			"interfaceid",
			"ip"
		]
	},
	"id": 1,
	"auth": "8ef873a332822d8acdf6b6f6e4fb2398"
}' | python -m json.tool 

检索指定ip主机

curl -s -X POST -H 'Content-Type: application/json-rpc' -d '{
	"jsonrpc": "2.0",
	"method": "host.get",
	"params": {
		"filter": {
			"host": [
				"10.2.33.100"
			]
		},
		"selectInterfaces": [
			"interfaceid",
			"ip"
		]
	},
	"id": 1,
	"auth": "8ef873a332822d8acdf6b6f6e4fb2398"
}' http://192.168.1.1/zabbix/api_jsonrpc.php | python -m json.tool 

3、使用api添加主机

curl -s -X POST -H 'Content-Type: application/json-rpc' -d '{
	"jsonrpc": "2.0",
	"method": "host.create",
	"params": {
		"host": "servername-192.168.1.2"
		"interfaces": [
		   {
			"type": 1,
			"main": 1,
			"useip": 1,
			"ip": "192.168.1.2",
			"dns": "",
			"port": "10050"
		    }
		],
		"groups": [
		    {
		        "groupid": "2"
		    }
		],
		"tags": [
		    {
		        "tag": "Host name",
			"value": "servername-192.168.1.2"
		    }
		],
		"templates": [
		    {
		        "templateid": "10001"
		    }
		]
	},
	"id": 1,
	"auth": "8ef873a332822d8acdf6b6f6e4fb2398"
}' http://192.168.1.1/zabbix/api_jsonrpc.php | python -m json.tool 

4、使用api删除主机

curl -s -X POST -H 'Content-Type: application/json-rpc' -d '{
	"jsonrpc": "2.0",
	"method": "host.delete",
	"params": [
	    "10065"
	],
	"id": 1,
	"auth": "8ef873a332822d8acdf6b6f6e4fb2398"
}' http://192.168.1.1/zabbix/api_jsonrpc.php | python -m json.tool 

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在 Kubernetes 中,我们可以使用 DaemonSet 来部署一个副本在每个节点上,并且这些副本会在特定节点上运行。这里我们以部署 Zabbix Server 和 Web UI 的情况为例,假设我们需要在节点 node2 上部署 Zabbix Server,并在所有节点上部署 Zabbix Web UI。 ### 部署 Zabbix Server 对于 Zabbix Server,我们将它作为一个 DaemonSet 并限制其部署到特定的节点(此处为 node2)。以下是使用 Zabbix Server 镜像 (`zabbix/zabbix-server-mysql`) 创建的 YAML 文件示例: ```yaml apiVersion: apps/v1 kind: DaemonSet metadata: name: zabbix-server-node2 spec: selector: matchLabels: app: zabbix-server template: metadata: labels: app: zabbix-server spec: nodeSelector: beta.kubernetes.io/os: ubuntu containers: - name: zabbix-server image: zabbix/zabbix-server-mysql command: ['zabbix_server'] args: ['-d'] ports: - containerPort: 10051 env: - name: MYSQL_ROOT_PASSWORD valueFrom: secretKeyRef: name: mysql-root-pass key: rootpass volumeMounts: - name: zabbix-data mountPath: /var/lib/zabbix volumes: - name: zabbix-data emptyDir: {} --- # 对应的 MySQL ServiceAccount 或 RoleBinding 可能需要在此处添加 ``` 这里的关键点是,我们指定了节点选择器 `beta.kubernetes.io/os: ubuntu` 并且设置了一个环境变量 `MYSQL_ROOT_PASSWORD` ,这个值应该来自于 `mysql-root-pass` 这个 Secret,用于 MySQL 数据库连接时验证根用户身份。 ### 部署 Zabbix Web UI 接下来,我们部署 Zabbix Web UI 到所有节点。这通常涉及使用 Nginx 和 MySQL 组件。为了简化起见,这里假定您已经有一个 MySQL 服务正在运行,并且有一个名为 `mysql-service` 的服务账号或角色绑定允许访问 MySQL。 下面是部署 Zabbix Web UI(包括 Nginx 和 MySQL 客户端)的 YAML 文件示例: ```yaml apiVersion: v1 kind: ServiceAccount metadata: name: zabbix-web-sa --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: zabbix-web-crb subjects: - kind: ServiceAccount name: zabbix-web-sa namespace: default roleRef: kind: ClusterRole name: cluster-admin apiGroup: rbac.authorization.k8s.io --- apiVersion: apps/v1 kind: Deployment metadata: name: zabbix-web spec: replicas: 1 selector: matchLabels: app: zabbix-web template: metadata: labels: app: zabbix-web spec: serviceAccountName: zabbix-web-sa containers: - name: zabbix-web-nginx-mysql image: zabbix/zabbix-web-nginx-mysql ports: - containerPort: 80 protocol: TCP env: - name: DB_SERVER value: mysql-service.default.svc.cluster.local - name: DB_USER valueFrom: secretKeyRef: name: mysql-user key: user - name: DB_PASSWORD valueFrom: secretKeyRef: name: mysql-pass key: password readinessProbe: httpGet: path: / port: 80 initialDelaySeconds: 30 periodSeconds: 10 livenessProbe: httpGet: path: / port: 80 initialDelaySeconds: 60 periodSeconds: 30 volumes: - name: zabbix-web-conf configMap: name: zabbix-web-config items: - key: default.conf path: default.conf --- apiVersion: v1 kind: ConfigMap metadata: name: zabbix-web-config data: default.conf: | # ... 配置内容 --- apiVersion: v1 kind: Service metadata: name: zabbix-web-service spec: type: LoadBalancer selector: app: zabbix-web ports: - name: web port: 80 targetPort: 80 ``` 以上 YAML 文件首先定义了必要的 RBAC 规则和服务账号,接着定义了 Deployment 负责启动 Zabbix Web UI 的容器,并配置了探针检查以确保容器健康。最后,我们创建了一个 ConfigMap 包含了 Web UI 的配置文件,并定义了一个负载均衡服务让外部能够访问 Web UI。 请注意,实际部署前应调整镜像标签和其他细节以匹配您的具体环境和需求。在运行这些 YAML 文件之前,请确保所有依赖项(如 MySQL)已经在 Kubernetes 环境中正确设置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

疯飙的蜗牛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值