Nagios Syntax Highlighting

 

 

Enabling Nagios syntax highlighting in vim

 

The Problem:

  • Nagios Object definitions and other configuration is well-known to be cumbersome and error-prone
  • Nagios Config files often consist of 100s of thousands of lines, and editing often requires changes in the middle of a file
  • For years people have Nagios throw errors at them on start because of tiny spelling mistakes

The Answer:

  • Vi IMproved (vim) lets you use self defined syntax highlighting to avoid common mistakes like missing braces
  • Pot meet kettle!

vim Config

Create a .vim directory and subdirectories

cd $OMD_ROOT
mkdir -p .vim .vim/ftdetect .vim/syntax

 

Define .cfg to be a Nagios config file

echo 'au BufRead,BufNewFile *.cfg set filetype=nagios' > .vim/ftdetect/nagios.vim

 

The Syntax file

Download the Nagios syntax highlighting support

wget -O.vim/syntax/nagios.vim \
'http://cvs.pld-linux.org/cgi-bin/viewvc.cgi/cvs/packages/vim-syntax-nagios/nagios.vim?revision=1.20&view=co'

 

 

Done!

Now enjoy a more helpful Nagios config:

...Unless you hate syntax highlighting, like me

 

What about Check_MK?

Check_MK Configurations are all-python so they do not need any of this.

VIM has automatic syntax highlighting for Check_MK built-in

..I use :syn off to turn it off

 

References:

http://www.vim.org/scripts/script.php?script_id=2261

http://vim.wikia.com/wiki/Creating_your_own_syntax_files

 

  • No labels