LoginSignup
6
7

More than 5 years have passed since last update.

Cisco IOSでコマンド実行ログを出力して検証を楽にする

Last updated at Posted at 2017-02-15

Ansibleなどの構成ツールや自動化ツールでネットワーク機器を操作するケースも増えてきました。Cisco IOS装置(ルータやスイッチ)上でのコマンド実行を自動化する検証やテストの際、実行された一連のコマンドを出力する設定をあらかじめIOSで行っておくと便利です。ただし、変更を伴うExecコマンドに対して有効ですが、showコマンドなどの状態確認やpingなどの実行コマンドについては対象外となります。

cisco
Router#show run | section archive
archive
 log config
  logging enable
  logging size 1000
  notify syslog contenttype plaintext
  hidekeys
Rotuer#

例えば、Ansibleで、以下のようなPlaybookを実行する場合。

playbook
  tasks:

    - name: Configure extended ACL to device
      ios_config:
        provider: "{{ cli }}"
        lines:
          - 10 permit ip host 1.1.1.1 any log
          - 20 permit ip host 2.2.2.2 any log
        parents: ip access-list extended test-ansible
        before: no ip access-list extended test-ansible
        match: exact
        timeout: 30
      register: result

Cisco Router上では以下のように出力されるので、コマンドが実行されたログがリアルタイムに確認できて便利です。

cisco
Router#
Feb 15 03:11:31.828: %PARSER-5-CFGLOG_LOGGEDCMD: User:cisco  logged command:!exec: enable
Feb 15 03:11:32.352: %PARSER-5-CFGLOG_LOGGEDCMD: User:cisco  logged command:no ip access-list extended test-ansible
Feb 15 03:11:32.445: %PARSER-5-CFGLOG_LOGGEDCMD: User:cisco  logged command:ip access-list extended test-ansible
Feb 15 03:11:32.521: %PARSER-5-CFGLOG_LOGGEDCMD: User:cisco  logged command:10 permit ip host 1.1.1.1 any log 
Feb 15 03:11:32.592: %PARSER-5-CFGLOG_LOGGEDCMD: User:cisco  logged command
Router#:20 permit ip host 2.2.2.2 any log 
Feb 15 03:11:32.627: %SYS-5-CONFIG_I: Configured from console by cisco on vty1 (10.70.233.120)
Router#

※Cisco IOSのArchiveセクションでは、他にも便利なオプションがあります。

cisco
Router(config-archive)#?
Archive configuration commands:
  default       Set a command to its defaults
  exit          Exit from archive configuration mode
  log           Logging commands
  maximum       maximum number of backup copies
  no            Negate a command or set its defaults
  path          path for backups
  rollback      Rollback parameters
  time-period   Period of time in minutes to automatically archive the
                running-config
  write-memory  Enable automatic backup generation during write memory

Router(config-archive)#log config 
Router(config-archive-log-cfg)#?
commands for controlling config logging:
  default   Set a command to its defaults
  exit      Exit from the log config submode
  hidekeys  suppress output (e.g. passwords) when displaying logged commands
  logging   Modify config logging parameters
  no        Negate a command or set its defaults
  notify    Send logged commands to target applications
  record    What to record in the config logger
6
7
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
6
7