1 Jul 2011 20:20
Re: SQL or script for active vlan on each switch
Thank you for sharing! I've tested it out and it appeared to do
exactly what I needed. I just need to customize it to display the
switch name instead of IDs.
-bn
0216331C
2011/6/30 Þórhallur Hálfdánarson <thorhallur.halfdanarson <at> ejs.is>:
> I believe this is what you're looking for...
>
> This is a PHP that return JSON with the VLAN list - feel free to use at will, or only extract the SQL :)
>
> <?PHP
> error_reporting(E_ALL);
> setLocale(LC_ALL, 'is_IS.utf8');
> define('_NETDOT', mysql_connect(host', user', 'pass'));
> mysql_select_db('netdot', _NETDOT);
>
> $ret = Array();
>
> $res = mysql_query('SELECT id, vid, name FROM vlan ORDER BY vid', _NETDOT);
> while ($a = mysql_fetch_assoc($res)) {
> $devices = Array();
> $res2 = mysql_query(sprintf('SELECT id FROM device WHERE id IN (SELECT device FROM interface
WHERE id IN (SELECT interface FROM interfacevlan WHERE vlan = %s))', $a['id']), _NETDOT);
> while ($d = mysql_fetch_assoc($res2)) {
> $devices[] = sprintf("'%s'", 'nd_'.$d['id']);
> }
> $ret[] = sprintf("'%s': { 'name': '%s', 'devices': [%s] }", $a['vid'], $a['name'],
implode(', ', $devices));
(Continue reading)
RSS Feed