headlines
Writing simple queries using SELECT and FROM
- Query 1: Introducing the simplest query
- Query 2: Adding a path in the
FROMclause - Query 3: Making
SELECTmore specific
Query 1: Introducing a simple query
To write one of the simplest queries — such a request for a list
of everything in the database — use SELECT
and FROM clauses like in SQL:
SELECT * FROM /
This query utilizes the following reserved words and symbols:
|
|
Describes the data that you want to see |
|
|
Generates everything known about the device similar to a wildcard;
it outputs the entire tree below the anchor-point indicated
in the |
|
|
Describes the anchor-point — the node in the tree that you want to pull data from |
|
|
Represents the root node when the slash is at the start of the path |
The results from the query depend on the database that you run it against. If you run this query against the sample batabase, it generates the results in the form of an inverted tree, showing the network and each device in it represented as a sub-tree. If you examine the database that this result came from, you'll see that it contains more information about some devices than about others, which is why some of the results appear more complete than others:
row:
*:
network:
device:
interface:
mac_address: 01:01:02:03:04:05
name: eth0
in_octets: 1995335536
out_octets: 248342455
oper_status: 1
system:
name: 5627
computed_vendor: LANIER
computed_model: 5627
computed_class: printer
computed_score: 115
os:
version: LANIER 5627 5.20
device:
interface:
mac_address: 02:A1:A2:A3:A4:A4
name: eth0
in_octets: 1229592351
out_octets: 1472928781
oper_status: 1
interface:
mac_address: 03:A1:A2:A3:A4:A5
name: eth1
in_octets: 0
out_octets: 0
oper_status: 0
system:
name: ESMITH
computed_vendor: Intel
computed_class: server
computed_score: 10
os:
version: Linux
device:
interface:
mac_address: 04:A1:A2:A3:A4:A8
name: eth0
in_octets: 1223098455
out_octets: 1523093749
oper_status: 1
interface:
mac_address: 05:A1:A2:A3:A4:A9
name: eth1
in_octets: 0
out_octets: 0
oper_status: 0
system:
name: AJONES
computed_vendor: Intel
computed_class: server
computed_score: 10
os:
version: Linux
device:
interface:
mac_address: 06:13:72:F3:0A:F5
name: eth0
in_octets: 0
out_octets: 0
oper_status: 2
interface:
mac_address: 07:13:72:F3:0A:F6
name: eth1
in_octets: 0
out_octets: 0
oper_status: 2
system:
computed_model: Ethernet Switch
computed_class: switch
computed_score: 25
os:
version: Ethernet Switch
device:
interface:
mac_address: 08:16:CB:FF:FE:66
name: eth0
in_octets: 0
out_octets: 346
oper_status: 1
interface:
mac_address: 09:16:CB:FF:FE:67
name: eth1
in_octets: 0
out_octets: 0
oper_status: 2
interface:
mac_address: 10:16:CB:FF:FE:68
name: eth2
in_octets: 0
out_octets: 0
oper_status: 2
interface:
mac_address: 11:16:CB:FF:FE:69
name: eth3
in_octets: 1598233842
out_octets: 2360815490
oper_status: 1
system:
name: PROTON
computed_model: Windows Workstation
computed_class: workstation
computed_score: 125
os:
version: Darwin Kernel Version 9.2.2
device:
interface:
mac_address: 12:10:D8:99:2B:C2
name: eth0
in_octets: 1385354750
out_octets: 1451321493
oper_status: 1
interface:
mac_address: 13:10:D8:99:2B:C1
name: eth1
in_octets: 3312952833
out_octets: 3239791359
oper_status: 1
system:
name: NISSINGETTY
computed_vendor: Juniper Networks
computed_model: Netscreen Router
computed_class: router
computed_score: 60
os:
version: NetScreen-5GT 5.1.043a
Query 2: Adding a path in the FROM clause
To add a level of specificity to this simple query, you can
write the path to a node level in the FROM clause.
This example asks for everything about the network:
SELECT * FROM /network/device
If you run this query on the Sample Database A, it generates the following devices, each represented as a separate tree:
row
*
interface
mac_address 01:01:02:03:04:05
name eth0
in_octets 1995335536
out_octets 248342455
oper_status 1
system
name 5627
computed_vendor LANIER
computed_model 5627
computed_class printer
computed_score 115
os
version LANIER 5627 5.20
row
*
interface
mac_address 02:A1:A2:A3:A4:A4
name eth0
in_octets 1229592351
out_octets 1472928781
oper_status 1
interface
mac_address 03:A1:A2:A3:A4:A5
name eth1
in_octets 0
out_octets 0
oper_status 0
system
name ESMITH
computed_vendor Intel
computed_class server
computed_score 10
os
version Linux
row
*
interface
mac_address 04:A1:A2:A3:A4:A8
name eth0
in_octets 1223098455
out_octets 1523093749
oper_status 1
interface
mac_address 05:A1:A2:A3:A4:A9
name eth1
in_octets 0
out_octets 0
oper_status 0
system
name AJONES
computed_vendor Intel
computed_class server
computed_score 10
os
version Linux
row
*
interface
mac_address 06:13:72:F3:0A:F5
name eth0
in_octets 0
out_octets 0
oper_status 2
interface
mac_address 07:13:72:F3:0A:F6
name eth1
in_octets 0
out_octets 0
oper_status 2
system
computed_model Ethernet Switch
computed_class switch
computed_score 25
os
version Ethernet Switch
row
*
interface
mac_address 08:16:CB:FF:FE:66
name eth0
in_octets 0
out_octets 346
oper_status 1
interface
mac_address 09:16:CB:FF:FE:67
name eth1
in_octets 0
out_octets 0
oper_status 2
interface
mac_address 10:16:CB:FF:FE:68
name eth2
in_octets 0
out_octets 0
oper_status 2
interface
mac_address 11:16:CB:FF:FE:69
name eth3
in_octets 1598233842
out_octets 2360815490
oper_status 1
system
name KRYPTON
computed_model Windows Workstation
computed_class workstation
computed_score 125
os
version Darwin Kernel Version 9.2.2
row
*
interface
mac_address 12:10:D8:99:2B:C2
name eth0
in_octets 1385354750
out_octets 1451321493
oper_status 1
interface
mac_address 13:10:D8:99:2B:C1
name eth1
in_octets 3312952833
out_octets 3239791359
oper_status 1
system
name NISSINGETTY
computed_vendor Juniper Networks
computed_model Netscreen Router
computed_class router
computed_score 60
os
version NetScreen-5GT 5.1.043a
Query 3: Making SELECT more specific
To add specificity to this simple query, you can write a specific path to a
node in the FROM clause. But you can get much more specific results by narrowing
the SELECT clause. Replace the * star with exactly what you want to
know, such as name, MAC address, and oeprating status:
SELECT name, mac_address, oper_status FROM /network/device/interface
Based on the sample database, this query generates a list of interface names:
row name eth0 mac_address 01:01:02:03:04:05 oper_status 1 row name eth0 mac_address 02:A1:A2:A3:A4:A4 oper_status 1 row name eth1 mac_address 03:A1:A2:A3:A4:A5 oper_status 0 row name eth0 mac_address 04:A1:A2:A3:A4:A8 oper_status 1 row name eth1 mac_address 05:A1:A2:A3:A4:A9 oper_status 0 row name eth0 mac_address 06:13:72:F3:0A:F5 oper_status 2 row name eth1 mac_address 07:13:72:F3:0A:F6 oper_status 2 row name eth0 mac_address 08:16:CB:FF:FE:66 oper_status 1 row name eth1 mac_address 09:16:CB:FF:FE:67 oper_status 2 row name eth2 mac_address 10:16:CB:FF:FE:68 oper_status 2 row name eth3 mac_address 11:16:CB:FF:FE:69 oper_status 1 row name eth0 mac_address 12:10:D8:99:2B:C2 oper_status 1 row name eth1 mac_address 13:10:D8:99:2B:C1 oper_status 1
Note: Each row in the above results is actually a tree, although it may
not look like it. In LISP-like string format, these trees would look like this:
(name = 'eth0')(name = 'eth1')(name = 'eth2')(name = 'eth3'), and
so on.

