Skip to content

Commit

Permalink
Merge pull request #351 from bufanda/xcp-ng
Browse files Browse the repository at this point in the history
XCP-NG Template Update
  • Loading branch information
igorbach authored Jul 26, 2024
2 parents aca3502 + 9b8e2cc commit acf6438
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 62 deletions.
114 changes: 83 additions & 31 deletions Virtualization/xcp-ng/6.0/template_app_xenorchestra.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
zabbix_export:
version: '6.0'
date: '2024-01-24T10:01:43Z'
date: '2024-04-12T07:47:42Z'
groups:
- uuid: 1b837a3c078647049a0c00c61b4d57b5
name: Hypervisors
Expand Down Expand Up @@ -631,35 +631,61 @@ zabbix_export:
var params = JSON.parse(value);
var req = new HttpRequest();
req.addHeader('Cookie: authenticationToken=' + params.token);
var response = req.get(encodeURI(params.url + '/rest/v0/backup/jobs/vm'));
var server_url = params.url.endsWith('/') ? params.url.slice(0, -1) : params.url;
var response = req.get(encodeURI(server_url + '/rest/v0/backup/jobs/vm'));
} catch(error) {
Zabbix.log(3, "XenOrchestra API failes" + params.url + "/rest/v0/backup/jobs/vm Error: " + error);
Zabbix.log(3, "XenOrchestra API failes" + server_url + "/rest/v0/backup/jobs/vm Error: " + error);
if (!Number.isInteger(error))
return 520;
}
var retVal = []
for (r=0; r < JSON.parse(response).length; r++) {
resp = req.get(encodeURI(params.url + JSON.parse(response)[r]));
srInfo = JSON.parse(resp);
retVal.push({"url": JSON.parse(response)[r], "uuid": srInfo.uuid, 'name': srInfo.name_label});
resp = req.get(encodeURI(server_url + JSON.parse(response)[r]));
backupInfo = JSON.parse(resp);
retVal.push({'url': JSON.parse(response)[r], 'uuid': backupInfo.id, 'name': backupInfo.name});
}
return JSON.stringify(retVal);
lifetime: 1d
item_prototypes:
- uuid: b16275be3b5741d9b199b3965856c86f
name: 'SR {#BACKUP.NAME} ({#BACKUP.UUID}): Get Values'
type: HTTP_AGENT
name: 'Backup {#BACKUP.NAME} ({#BACKUP.UUID}): Get job status'
type: SCRIPT
key: 'xoa.backup.raw[{#BACKUP.UUID}]'
delay: 15m
history: '0'
history: 1d
trends: '0'
value_type: TEXT
url: '{$XOA.URL}{#BACKUP.URL}'
headers:
- name: Cookie
value: 'authenticationToken={$XOA.AUTH.TOKEN}'
- name: Accept
value: application/json
params: |
try {
var params = JSON.parse(value);
var req = new HttpRequest();
req.addHeader('Cookie: authenticationToken=' + params.token);
var server_url = params.url.endsWith('/') ? params.url.slice(0, -1) : params.url;
var response = req.get(encodeURI(server_url + '/rest/v0/backup/logs'));
} catch(error) {
Zabbix.log(3, "XenOrchestra API failes" + server_url + "/rest/v0/backup/logs Error: " + error);
if (!Number.isInteger(error))
return 520;
}
var retVal = []
for (r=0; r < JSON.parse(response).length; r++) {
resp = req.get(encodeURI(server_url + JSON.parse(response)[r]));
backupLog = JSON.parse(resp);
if (backupLog.jobID == params.uuid && backupLog.status != 'pending')
retVal.push({"url": JSON.parse(response)[r], "id": backupLog.id, 'name': backupLog.jobName, 'status': backupLog.status, 'start': backupLog.start, 'end': backupLog.end});
else
retVal.push({"url": JSON.parse(response)[r], "id": backupLog.id, 'name': backupLog.jobName, 'status': backupLog.status, 'start': backupLog.start});
retVal.reverse(function(a,b){return a.start - b.start});
}
return JSON.stringify(retVal[0]);
timeout: 60s
parameters:
- name: token
value: '{$XOA.AUTH.TOKEN}'
- name: url
value: '{$XOA.URL}'
- name: uuid
value: '{#BACKUP.UUID}'
parameters:
- name: token
value: '{$XOA.AUTH.TOKEN}'
Expand All @@ -682,20 +708,21 @@ zabbix_export:
var params = JSON.parse(value);
var req = new HttpRequest();
req.addHeader('Cookie: authenticationToken=' + params.token);
var response = req.get(encodeURI(params.url + '/rest/v0/hosts'));
var server_url = params.url.endsWith('/') ? params.url.slice(0, -1) : params.url;
var response = req.get(encodeURI(server_url + '/rest/v0/hosts'));
} catch(error) {
Zabbix.log(3, "XenOrchestra API failes" + params.url + "/rest/v0/hosts Error: " + error);
Zabbix.log(3, "XenOrchestra API failes" + server_url + "/rest/v0/hosts Error: " + error);
if (!Number.isInteger(error))
return 520;
}
var retVal = []
for (r=0; r < JSON.parse(response).length; r++) {
try {
resp = req.get(encodeURI(params.url + JSON.parse(response)[r]));
resp = req.get(encodeURI(server_url + JSON.parse(response)[r]));
hostInfo = JSON.parse(resp);
retVal.push({"url": JSON.parse(response)[r], "uuid": hostInfo.uuid, 'name': hostInfo.name_label});
} catch(error) {
Zabbix.log(3, "XenOrchestra API failes" + params.url + "/rest/v0/hosts Error: " + error);
Zabbix.log(3, "XenOrchestra API failes" + server_url + "/rest/v0/hosts Error: " + error);
if(!Number.isInteger(error))
return 500;
}
Expand Down Expand Up @@ -745,20 +772,21 @@ zabbix_export:
var params = JSON.parse(value);
var req = new HttpRequest();
req.addHeader('Cookie: authenticationToken=' + params.token);
var response = req.get(encodeURI(params.url + '/rest/v0/pools'));
var server_url = params.url.endsWith('/') ? params.url.slice(0, -1) : params.url;
var response = req.get(encodeURI(server_url + '/rest/v0/pools'));
} catch(error) {
Zabbix.log(3, "XenOrchestra API failes" + params.url + "/rest/v0/pools Error: " + error);
Zabbix.log(3, "XenOrchestra API failes" + server_url + "/rest/v0/pools Error: " + error);
if (!Number.isInteger(error))
return 520;
}
var retVal = []
for (r=0; r < JSON.parse(response).length; r++) {
try {
resp = req.get(encodeURI(params.url + JSON.parse(response)[r]));
resp = req.get(encodeURI(server_url + JSON.parse(response)[r]));
poolInfo = JSON.parse(resp);
retVal.push({"url": JSON.parse(response)[r], "uuid": poolInfo.uuid, 'name': poolInfo.name_label});
} catch(error) {
Zabbix.log(3, "XenOrchestra API failes" + params.url + "/rest/v0/pools Error: " + error);
Zabbix.log(3, "XenOrchestra API failes" + server_url + "/rest/v0/pools Error: " + error);
if (!Number.isInteger(error))
return 520;
}
Expand Down Expand Up @@ -869,20 +897,21 @@ zabbix_export:
var params = JSON.parse(value);
var req = new HttpRequest();
req.addHeader('Cookie: authenticationToken=' + params.token);
var response = req.get(encodeURI(params.url + '/rest/v0/srs'));
var server_url = params.url.endsWith('/') ? params.url.slice(0, -1) : params.url;
var response = req.get(encodeURI(server_url + '/rest/v0/srs'));
} catch(error) {
Zabbix.log(3, "XenOrchestra API failes" + params.url + "/rest/v0/srs Error: " + error);
Zabbix.log(3, "XenOrchestra API failes" + server_url + "/rest/v0/srs Error: " + error);
if (!Number.isInteger(error))
return 520;
}
var retVal = []
for (r=0; r < JSON.parse(response).length; r++) {
try {
resp = req.get(encodeURI(params.url + JSON.parse(response)[r]));
resp = req.get(encodeURI(server_url + JSON.parse(response)[r]));
srInfo = JSON.parse(resp);
retVal.push({"url": JSON.parse(response)[r], "uuid": srInfo.uuid, 'name': srInfo.name_label});
} catch(error) {
Zabbix.log(3, "XenOrchestra API failes" + params.url + "/rest/v0/srs Error: " + error);
Zabbix.log(3, "XenOrchestra API failes" + server_url + "/rest/v0/srs Error: " + error);
if (!Number.isInteger(error))
return 520;
}
Expand Down Expand Up @@ -1031,20 +1060,21 @@ zabbix_export:
var params = JSON.parse(value);
var req = new HttpRequest();
req.addHeader('Cookie: authenticationToken=' + params.token);
var response = req.get(encodeURI(params.url + '/rest/v0/vms'));
var server_url = params.url.endsWith('/') ? params.url.slice(0, -1) : params.url;
var response = req.get(encodeURI(server_url + '/rest/v0/vms'));
} catch(error) {
Zabbix.log(3, "XenOrchestra API failes" + params.url + "/rest/v0/vms Error: " + error);
Zabbix.log(3, "XenOrchestra API failes" + server_url + "/rest/v0/vms Error: " + error);
if (!Number.isInteger(error))
return 520;
}
var retVal = []
for (r=0; r < JSON.parse(response).length; r++) {
try {
resp = req.get(encodeURI(params.url + JSON.parse(response)[r]));
resp = req.get(encodeURI(server_url + JSON.parse(response)[r]));
vmsInfo = JSON.parse(resp);
retVal.push({"url": JSON.parse(response)[r], "uuid": vmsInfo.uuid, 'name': vmsInfo.name_label});
} catch(error) {
Zabbix.log(3, "XenOrchestra API failes" + params.url + "/rest/v0/vms Error: " + error);
Zabbix.log(3, "XenOrchestra API failes" + server_url + "/rest/v0/vms Error: " + error);
if (!Number.isInteger(error))
return 520;
}
Expand Down Expand Up @@ -1084,6 +1114,21 @@ zabbix_export:
path: $.url
- lld_macro: '{#VMS.UUID}'
path: $.uuid
httptests:
- uuid: 1458d489beef4863be6f18f36ac41a24
name: 'Check Token Validity'
delay: 5m
attempts: '3'
headers:
- name: Cookie
value: 'authenticationToken={$XOA.AUTH.TOKEN}'
- name: Accept
value: application/json
steps:
- name: 'Check Token Validity'
url: '{$XOA.URL}/rest/v0'
follow_redirects: 'NO'
status_codes: '200'
tags:
- tag: component
value: hypervisor
Expand All @@ -1110,3 +1155,10 @@ zabbix_export:
newvalue: 'true'
- value: '0'
newvalue: 'false'
triggers:
- uuid: 728078ed899548faa3736110abb9d69e
expression: 'last(/Xen Orchestra by HTTP/web.test.rspcode[Check Token Validity,Check Token Validity])=401'
recovery_mode: RECOVERY_EXPRESSION
recovery_expression: 'last(/Xen Orchestra by HTTP/web.test.rspcode[Check Token Validity,Check Token Validity])=200'
name: 'Authentication Token for XenOrchestra is invalid'
priority: HIGH
Loading

0 comments on commit acf6438

Please sign in to comment.