Last active
June 11, 2024 19:17
-
-
Save Jcpetrucci/34f23aaa62561cb7507f56ebf6765b93 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
string_searching="Searching..." | |
HISTFILE=~/d42-search-history.txt | |
history -r "$HISTFILE" | |
echo $(tput setaf 7) | |
trap "echo $(tput sgr0)" EXIT | |
while read -r -e -p '? ' name; do | |
history -s "$name" | |
history -w "$HISTFILE" | |
printf '%s\r' "$string_searching" >&2 | |
curl --netrc -s -X POST -d 'header=yes' --data-urlencode 'query=SELECT d.name as device_name, | |
SUBSTRING(a.alias_name,1,10) as alias, | |
i.ip_address, | |
d.cpucount as sockets, | |
d.cpucore as cores, | |
CONCAT (d.ram, d.ram_size_type) as ram, | |
CONCAT (d.hard_disk_size, d.hard_disk_size_type) as disk, | |
REGEXP_REPLACE(SUBSTRING(d.notes,1,100),'"'[\n\r]'"','"' '"','"'g'"') as notes, | |
d.first_added, | |
s.name as subnet | |
from view_device_v1 d | |
left join view_ipaddress_v1 i on i.device_fk = d.device_pk | |
left join view_devicealias_v1 a on a.device_fk = d.device_pk | |
inner join view_subnet_v1 s on i.subnet_fk = s.subnet_pk | |
WHERE LOWER( d.name ) like '"'%${name}%'"' | |
OR LOWER ( a.alias_name ) LIKE '"'%${name}%'"' | |
OR LOWER ( d.notes) LIKE '"'%${name}%'"' | |
order by d.name' 'https://ipam.optiv.com/services/data/v1.0/query/' 2>&1 | column --table --separator , | |
done</proc/self/fd/0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment