LoginSignup
1
3

More than 5 years have passed since last update.

【ツール紹介】netdisco

Posted at

netdisco

スイッチ/ルータのポート管理ツール。
SNMPを利用してスイッチのポート一覧を出してくれるツール。
VLANやポートの状態も取得してくれる。

CPAN: https://metacpan.org/pod/App::Netdisco
github: https://github.com/netdisco/netdisco
デモサイト https://netdisco2-demo.herokuapp.com/

日本語ドキュメントというかドキュメントがCPANにしかない気がする。
必要な情報はすべてCPANのページに書いてある。優秀。

試験的に入れてみた

データセンターの集約SWの情報を取得。
catalyst 6500/6800 を10台程度取得した。
EX4200/4300も5台ほど取得できた。

  • ポート一覧は1台ずつの表示なのでこの程度ならサクサク
  • VLAN一覧は取れるものの、VLANのアドレスは一覧では分からないので残念

環境(Env)

  • CentOS6
  • postgresql
  • perl

install

  • パッケージ
# yum install perl-core perl-DBD-Pg net-snmp-perl net-snmp-devel openssl-devel make automake gcc
  • postgres
# yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-3.noarch.rpm
# yum install postgresql96 postgresql96-devel 
# yum install postgresql96-server

# vi /var/lib/pgsql/9.6/data/pg_hba.conf

# service postgresql-9.6 initdb
# chkconfig postgresql-9.6 on
# service postgresql-9.6 start
pg_hba.confの差分
[localhost:root/509]# diff .backup/pg_hba.conf.org pg_hba.conf
80c80
< local   all             all                                     peer
---
> local   all             all                                     trust
82c82
< host    all             all             127.0.0.1/32            ident
---
> host    all             all             127.0.0.1/32            md5
[localhost:root/510]#
  • netdisco実行用system/postgres user作成
# useradd -m -s /bin/bash netdisco
# passwd netdisco  ## systemのnetdiscoユーザのパスワード設定

# su - postgres
$ createuser -DRSP netdisco
$ createdb -O netdisco netdisco
$ exit

# su - netdisco

$ echo 'export PATH=$PATH:/usr/pgsql-9.6/bin/' >> ~/.bashrc
$ source ~/.bashrc
  • netdisco install
    cpanmを実行するだけ
# su - netdisco

$ curl -L https://cpanmin.us/ | perl - --notest --local-lib ~/perl5 App::Netdisco

$ mkdir ~/bin/
$ ln -s ~/perl5/bin/{localenv,netdisco-*} ~/bin/
$ ~/bin/netdisco-backend status    ### 動くか確認のみ
  • config修正
$ mkdir ~/environments
$ cp -ip ~/perl5/lib/perl5/auto/share/dist/App-Netdisco/environments/deployment.yml ~/environments
$ chmod 600 ~/environments/deployment.yml
$ vi ~/environments/deployment.yml

postgresのユーザとパス、取得装置のsnmpCommunityを変更

deployment.ymlのdiff
[netdisco@localhost ~]$ diff ~/perl5/lib/perl5/auto/share/dist/App-Netdisco/environments/deployment.yml ~/environments/deployment.yml
13,15c13,15
<   user: 'changeme'
<   pass: 'changeme'
<   #host: 'localhost'
---
>   user: 'netdisco'
>   pass: 'netdisco'
>   host: '127.0.0.1'
34,35c34,35
<   - tag: 'default_v2_readonly'
<     community: 'public'
---
>   - tag: 'Community'
>     community: 'hogefuga'
[netdisco@localhost ~]$
  • 起動
$ netdisco-backend start
$ netdisco-web start

あとはweb-UIからでも見れる、CLIでも叩けるのでお好きな方で。

ポーリング

デフォルトでの自動ポーリングはなし
cron形式で登録する
https://metacpan.org/pod/distribution/App-Netdisco/lib/App/Netdisco/Manual/Configuration.pod#schedule

またはweb-UIからdiscoverってボタンを押せば更新してくれる

機器毎に取得時間をずらしたいなどの場合は
cronに netdisco-do discover -d [host] を登録しておけば頑張れそうな予感。

余談1 Postgresが壊れた時用

  • データ領域削除
# service postgresql-9.6 stop
# rm -rf /var/lib/pgsql/9.6/data/
  • データ領域再構築
# su - postgres
$ whoami
$ /usr/pgsql-9.6/bin/initdb -D /var/lib/pgsql/9.6/data
$ ls -l /var/lib/pgsql/9.6/data
$ exit

バックアップをとってなければ上記の通り修正すればいい。
# cp -ip /var/lib/pgsql/backups/pg_hba.conf /var/lib/pgsql/9.6/data/
# service postgresql-9.6 start
  • netdiscoの再起動
# su - netdisco
$ whoami

$ netdisco-web stop
$ netdisco-backend stop

$ netdisco-backend start
$ netdisco-web start

snmpで最新の状態を再取得すればいいだけなので、特にdumpしない運用でもよさげなので素敵。
あまりにも管理機器数が多い場合はrestoreした方がいいとかケースバイケースかしら。
DB上のWEB-UIからのnetdisco操作ログが吹っ飛ぶとかその程度の被害だと思います。

バックアップをとるならbasebackupが楽(pg_hba.conf的な意味で)

その他

SNMPがリードオンリーでない場合、AdminアカウントならWEB-UI上からポートの起動/停止ができるので、
Admin権限のないアカウントを作った方がよさそう。
Admin権限がないとdiscoverも実行不可だけど、悪戯や操作ミスは防げる。

LLDPを有効にしてないので全機能が使えてるわけではないけど、
それでもポート管理表としては問題なさそうでした。

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3