You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2025-03-31 16:44:49

Zakkya
Member
Registered: 2025-03-31
Posts: 1

Récupérer la liste des "Computers" et leur "OS"

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 smile

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

Board footer

Powered by FluxBB