You are not logged in.
Pages: 1
Salut à tous,
J'ai bien galéré aujourd'hui à trouver comment récupérer la liste des "Computers" et leur "OS"
J'ai vu 2, 3 posts sur le forum mais rien de bien concluant ...
Mais voici mon script, qui fonctionne et que je partage à vous autres
Pensez à bien remplacer les champs "replaceMe" par votre config
#!/bin/bash
glpiApiUrl="https://replaceMe/apirest.php"
appToken="replaceMe"
userToken="replaceMe"
moreThanTotalComputer=100
sessionToken=$(curl -s -k -X GET \
-H 'Content-Type: application/json' \
-H "Authorization: user_token $userToken" \
-H "App-Token: $appToken" \
"${glpiApiUrl}/initSession" | jq -r ".[]")
f_computerAndOs()
{
curl -s -k -X GET \
-H 'Content-Type: application/json' \
-H "Session-Token: $sessionToken" \
-H "App-Token: $appToken" \
"${glpiApiUrl}/Item_OperatingSystem/?expand_dropdowns=true&range=0-${moreThanTotalComputer}" | jq -r ".[] | .items_id, .operatingsystems_id"
}
#f_computerAndOs
f_computerAndOsIgnoreNoUser()
{
# Ignoring computers without associated user
computerList=$(curl -s -k -X GET \
-H 'Content-Type: application/json' \
-H "Session-Token: $sessionToken" \
-H "App-Token: $appToken" \
"${glpiApiUrl}/Computer/?range=0-${moreThanTotalComputer}" | jq -r '.[] | select(.users_id != 0) .name')
for computer in $computerList ; do
curl -s -k -X GET \
-H 'Content-Type: application/json' \
-H "Session-Token: $sessionToken" \
-H "App-Token: $appToken" \
"${glpiApiUrl}/Item_OperatingSystem/?expand_dropdowns=true&range=0-${moreThanTotalComputer}" | jq -r ".[] | select(.\"items_id\" == \"$computer\") | .items_id, .operatingsystems_id"
done
}
f_computerAndOsIgnoreNoUser
Last edited by Zakkya (2025-03-31 17:37:42)
Offline
Pages: 1