Thursday, June 9, 2011

Whatsup Gold -- Back-End SQL for device attributes

I hate maintaining spreadsheets when my group and I have documented our network via whatsup gold. However, extracting that information for various reason has been a pain. I use this script on the back-end to grab devices by campus with the svalues (our defined attributes of importance). FYI, I'm not a SQL person by any stretch. I'm sure the code could be much better (and I'll take the helpful tips). AssetTag and GPTAG are -usually- the same value for us. replace sName = with your values and you should have some luck. Change the sNetworkAddress = to your subnets, etc.
No idea how to pull this into a webpage. I tried. It blew up. We needed the extract in csv so this was good enough. YMMV. I am not an expert. Use at your own risk.



SELECT DISTINCT Device.sDisplayName as DisplayName
,NetworkInterface.sNetworkAddress AS IPAddress
,(SELECT DeviceAttribute.sValue FROM DeviceAttribute WHERE DeviceAttribute.sName = 'SerialNumber' AND (DeviceAttribute.nDeviceID = Device.nDeviceID)) as SerialNumber
,(SELECT DeviceAttribute.sValue FROM DeviceAttribute WHERE DeviceAttribute.sName = 'Name' AND (DeviceAttribute.nDeviceID = Device.nDeviceID)) as Hostname,
(SELECT DeviceAttribute.sValue FROM DeviceAttribute WHERE DeviceAttribute.sName = 'Location' AND (DeviceAttribute.nDeviceID = Device.nDeviceID))AS Location,
(SELECT DeviceAttribute.sValue FROM DeviceAttribute WHERE DeviceAttribute.sName = 'Model' AND (DeviceAttribute.nDeviceID = Device.nDeviceID)) AS Model,
(SELECT DeviceAttribute.sValue FROM DeviceAttribute WHERE DeviceAttribute.sName = 'GPTAG' AND (DeviceAttribute.nDeviceID = Device.nDeviceID)) AS GPTAG,
(SELECT DeviceAttribute.sValue FROM DeviceAttribute WHERE DeviceAttribute.sName = 'AssetTag' AND (DeviceAttribute.nDeviceID = Device.nDeviceID)) AS AssetTag,
(SELECT DeviceAttribute.sValue FROM DeviceAttribute WHERE DeviceAttribute.sName = 'MACAddress' AND (DeviceAttribute.nDeviceID = Device.nDeviceID)) AS MACAddress
FROM Device JOIN DeviceAttribute ON Device.nDeviceID = DeviceAttribute.nDeviceIDJOIN NetworkInterface ON Device.nDeviceID = NetworkInterface.nDeviceID
WHERE NetworkInterface.sNetworkAddress LIKE '10.63%'ORDER BY IPAddress


PS -- I can send you the raw sql if you desire. Learning mode....

1 comment:

  1. This is great stuff. Have you thought about sharing it on the WUGspace community? That is all things WhatsUp Gold related. Here is the URL:

    http://community.whatsupgold.com

    Cheers,
    The WhatsUp Guru

    ReplyDelete