Ausgabe filtern
Hallo zusammen,
Ich schreib gerade an einem Skript für Abfragen aus dem Programm Device42, mit Hilfe folgendes Befehles
Erhalte ich untenstehende Ausgabe, ich würde gerne die Ausgabe soweit filtern, das ich als Output nur die Seriennummer oder das Hardware Modell habe. Hat wer eine Idee wie ich das anstellen kann ?
Vielen Dank !
{
"aliases": [
"D42-esxiII.device42.pvt"
],
"asset_no": "",
"building": "West Haven Office",
"category": Hypervisors,
"cpucore": 8,
"cpucount": 2,
"cpuspeed": 2270.0,
"custom_fields": ,
"customer": "autodiscovery",
"customer_id": 1,
"device_external_links": ,
"device_id": 534,
"device_purchase_line_items": ,
"hdd_details": null,
"hddcount": "",
"hddraid": null,
"hddraid_type": null,
"hddsize": "",
"hw_depth": 2,
"hw_model": "ProLiant DL360 G7",
"hw_size": 1.0,
"id": 534,
"in_service": true,
"ip_addresses": [
{
"ip": "192.168.11.70",
"label": "vmk0",
"macaddress": "78:e3:b5:0d:e1:94",
"subnet": "West Haven Network-192.168.11.0/24",
"subnet_id": 1,
"type": 1
},
{
"ip": "192.168.11.71",
"label": "mgmt",
"subnet": "West Haven Network-192.168.11.0/24",
"subnet_id": 1,
"type": 1
},
{
"ip": "fe80::7ae3:b5ff:fe0d:e194",
"label": "vmk0",
"macaddress": "78:e3:b5:0d:e1:94",
"subnet": "undefined-::/0",
"subnet_id": 3,
"type": null
}
],
"last_updated": "2016-09-21T03:59:07.621Z",
"mac_addresses": [
{
"mac": "78:e3:b5:0d:e1:94",
"port": "GigabitEthernet4/0/13 @ wh-lab-sw-01",
"port_name": "vmnic0, vmk0",
"vlan": "VLAN0020"
},
{
"mac": "78:e3:b5:0d:e1:92",
"port": null,
"port_name": "vmnic3",
"vlan": null
},
{
"mac": "78:e3:b5:0d:e1:90",
"port": null,
"port_name": "vmnic2",
"vlan": null
},
{
"mac": "78:e3:b5:0d:e1:96",
"port": null,
"port_name": "vmnic1",
"vlan": null
}
],
"manufacturer": "HP",
"name": "D42-esxiII",
"notes": "",
"orientation": 1,
"os": "VMware ESXi",
"osver": "5.5.0",
"osverno": "2403361",
"rack": "Lab Rack",
"rack_id": 1,
"ram": 32768.0,
"room": "Server Closet",
"serial_no": "CZ3128LL62",
"service_level": "Production",
"start_at": 40.0,
"tags": [
"labrack"
],
"type": "physical",
"ucs_manager": null,
"uuid": "32393735-3733-5a43-3331-32384c4c3632",
"virtual_host_name": null,
"where": 5,
"xpos": 0
}
Ich schreib gerade an einem Skript für Abfragen aus dem Programm Device42, mit Hilfe folgendes Befehles
curl -X GET -u 'admin:adm!nd42' https://yourdevice42address/api/1.0/devices/name/<device-name#>/ --insecure
Erhalte ich untenstehende Ausgabe, ich würde gerne die Ausgabe soweit filtern, das ich als Output nur die Seriennummer oder das Hardware Modell habe. Hat wer eine Idee wie ich das anstellen kann ?
Vielen Dank !
{
"aliases": [
"D42-esxiII.device42.pvt"
],
"asset_no": "",
"building": "West Haven Office",
"category": Hypervisors,
"cpucore": 8,
"cpucount": 2,
"cpuspeed": 2270.0,
"custom_fields": ,
"customer": "autodiscovery",
"customer_id": 1,
"device_external_links": ,
"device_id": 534,
"device_purchase_line_items": ,
"hdd_details": null,
"hddcount": "",
"hddraid": null,
"hddraid_type": null,
"hddsize": "",
"hw_depth": 2,
"hw_model": "ProLiant DL360 G7",
"hw_size": 1.0,
"id": 534,
"in_service": true,
"ip_addresses": [
{
"ip": "192.168.11.70",
"label": "vmk0",
"macaddress": "78:e3:b5:0d:e1:94",
"subnet": "West Haven Network-192.168.11.0/24",
"subnet_id": 1,
"type": 1
},
{
"ip": "192.168.11.71",
"label": "mgmt",
"subnet": "West Haven Network-192.168.11.0/24",
"subnet_id": 1,
"type": 1
},
{
"ip": "fe80::7ae3:b5ff:fe0d:e194",
"label": "vmk0",
"macaddress": "78:e3:b5:0d:e1:94",
"subnet": "undefined-::/0",
"subnet_id": 3,
"type": null
}
],
"last_updated": "2016-09-21T03:59:07.621Z",
"mac_addresses": [
{
"mac": "78:e3:b5:0d:e1:94",
"port": "GigabitEthernet4/0/13 @ wh-lab-sw-01",
"port_name": "vmnic0, vmk0",
"vlan": "VLAN0020"
},
{
"mac": "78:e3:b5:0d:e1:92",
"port": null,
"port_name": "vmnic3",
"vlan": null
},
{
"mac": "78:e3:b5:0d:e1:90",
"port": null,
"port_name": "vmnic2",
"vlan": null
},
{
"mac": "78:e3:b5:0d:e1:96",
"port": null,
"port_name": "vmnic1",
"vlan": null
}
],
"manufacturer": "HP",
"name": "D42-esxiII",
"notes": "",
"orientation": 1,
"os": "VMware ESXi",
"osver": "5.5.0",
"osverno": "2403361",
"rack": "Lab Rack",
"rack_id": 1,
"ram": 32768.0,
"room": "Server Closet",
"serial_no": "CZ3128LL62",
"service_level": "Production",
"start_at": 40.0,
"tags": [
"labrack"
],
"type": "physical",
"ucs_manager": null,
"uuid": "32393735-3733-5a43-3331-32384c4c3632",
"virtual_host_name": null,
"where": 5,
"xpos": 0
}
Please also mark the comments that contributed to the solution of the article
Content-Key: 327486
Url: https://administrator.de/contentid/327486
Printed on: April 24, 2024 at 01:04 o'clock
2 Comments
Latest comment
grep
oder am Ende statt mit awk mit
Da das JSON Code ist was du erhältst wäre es aber auch sinnvoll gleich einen JSON-Parser dazwischen zu schalten: z.B. https://stedolan.github.io/jq/
Alternativen finden sich hier: Parsing JSON with UNIX tools
Gruß mik
curl -X GET -u 'admin:adm!nd42' https://yourdevice42address/api/1.0/devices/name/<device-name#>/ --insecure | grep 'hw_model' | awk -F '"' '{print $4}'
..... | cut -d'"' -f4
Da das JSON Code ist was du erhältst wäre es aber auch sinnvoll gleich einen JSON-Parser dazwischen zu schalten: z.B. https://stedolan.github.io/jq/
Alternativen finden sich hier: Parsing JSON with UNIX tools
Gruß mik