Hi,
I am currently in the process of writing a script to send E-Mail notifications about the status of each VM's backup in Proxmox.
To do this I am using the following API URL to get the Tasks/Backup Jobs of the previous night:
The timestamp is autogenerated using PHP and is then inserted into the URL.
I used the optional "since" parameter a week ago and it work perfectly, however about 3 days ago a backup task for one of the VM's "Got stuck" for 3 days and we ended up having to manually end/cancel it.
This cancelled task when fetched via the API has a Start time of 1625835454 and an end time of 1626161424 (roughly 3 days in between timestamps).
This seems to have caused an issue with the API, when fetching the backup tasks for yesterday ( 24 hours ago ) no backup tasks are given/listed by the API even though other VM's created their backups successfully, however when fetching the backup tasks from 4 days ago the API then gives a list of the backup tasks created yesterday and the cancelled backup task.
Below is the code I used to connect to the API:
I have attached the output from the function from a print_r() on the $data variable.
I am currently in the process of writing a script to send E-Mail notifications about the status of each VM's backup in Proxmox.
To do this I am using the following API URL to get the Tasks/Backup Jobs of the previous night:
Code:
https://prx-backup.local:8007/api2/json/nodes/prx-backup/tasks?since=1626091200
The timestamp is autogenerated using PHP and is then inserted into the URL.
I used the optional "since" parameter a week ago and it work perfectly, however about 3 days ago a backup task for one of the VM's "Got stuck" for 3 days and we ended up having to manually end/cancel it.
This cancelled task when fetched via the API has a Start time of 1625835454 and an end time of 1626161424 (roughly 3 days in between timestamps).
This seems to have caused an issue with the API, when fetching the backup tasks for yesterday ( 24 hours ago ) no backup tasks are given/listed by the API even though other VM's created their backups successfully, however when fetching the backup tasks from 4 days ago the API then gives a list of the backup tasks created yesterday and the cancelled backup task.
Below is the code I used to connect to the API:
Code:
function get_backup_tasks() {
// generate a timestamp for the previous day
$hour = 12;
$today = strtotime($hour . ':00:00');
// Below timestamp does not give any tasks (used to work)
$yesterday = strtotime('-1 day', $today);
// Below timestamp works since the "stuck" backup task was cancelled
$yesterday = strtotime('-4 day', $today);
// get a list of backups/tasks performed since yesterday
$ch = curl_init();
$api_task_url = "https://prx-backup.local:8007/api2/json/nodes/prx-backup/tasks?since=".$yesterday;
echo $api_task_url."\n";
$header = array(
'Accept: application/json',
'Authorization: PBSAPIToken= =========== Token comes here ========'
);
curl_setopt($ch, CURLOPT_URL, $api_task_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$output=curl_exec($ch);
curl_close($ch);
$data=json_decode($output, true);
return $data;
}
I have attached the output from the function from a print_r() on the $data variable.