1. 添加主机
from icinga2 import Icinga2API
api = Icinga2API(username="root", password="12345678gdfgdf", url="https://xxx.xxx.xxx.xxx:5665")
data = {
"name": "192.168.1.100",
"template": ["generic-host"],
"attrs": {
"name": "192.168.1.100",
"address": "192.168.1.100",
"check_command": "hostalive"
}
}
api.hosts.add(data)
2. 添加主机组
api = Icinga2API(username="root", password="12345678gdfgdf", url="https://xxx.xxx.xxx.xxx:5665")
data = {
"attrs": {
"name": "GroupA",
"groups": ["GroupB", "GroupC"]
}
}
api.hostgroups.add(data)