//native
/**
* Delete maintenance
* Delete one or more maintenance windows by maintenanceid (maintenance.delete). Returns the deleted maintenanceids.
*/
export async function main(auth: RT.Zabbix, maintenance_ids: string[]) {
return await call(auth, "maintenance.delete", maintenance_ids)
}
async function call(auth: RT.Zabbix, method: string, params: any) {
const response = await fetch(
`${auth.base_url.replace(/\/+$/, "").replace(/\/api_jsonrpc\.php$/, "")}/api_jsonrpc.php`,
{
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json-rpc",
Accept: "application/json",
},
body: JSON.stringify({ jsonrpc: "2.0", method, params, id: 1 }),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const text = await response.text()
let data: any
try {
data = JSON.parse(text)
} catch {
throw new Error(
`Not a JSON-RPC response (check base_url): ${text.slice(0, 300)}`
)
}
if (data.error) {
throw new Error(
`${data.error.code} ${data.error.message} ${data.error.data ?? ""}`
)
}
return data.result
}
Submitted by hugo989 3 hours ago