#!/usr/bin/perl
#
# Dump Device Table to .csv file
# maxbaker - 11/12/09
#
# $Source: /cvsroot/netdisco/netdisco/bin/device_to_csv,v $
# $Id: device_to_csv,v 1.1 2009/11/12 17:25:56 maxbaker Exp $

use lib '/usr/share/netdisco';
use netdisco ':all';

config('/usr/share/netdisco/netdisco.conf');

$devices = sql_rows('device',['*']);

# Header Row - from first returned entry
@keys = keys %{$devices->[0]};
print join(',',@keys),"\n";

# Device Rows
foreach my $d (sort sort_ip @$devices) {
    my @val;
    foreach my $key (@keys) {
        push @val, $d->{$key};
    }
    print join(',',@val),"\n";
}
