Nagios Chinese display Solution

Source: Internet
Author: User

The Status Map function of Nagios displays the monitored network topology and the node device name on the node image. Unfortunately, the default Nagios does not support Chinese characters. For this reason, I have studied the source code of Nagios and GD for two days and finally found a solution. The details are as follows:

Decompress the Nagios Chinese source code package to nagios-3.0.3 for example), to achieve the network topology drawing source code file is nagios-3.0.3/cgi/statusmap. c. After compilation and installation, this file corresponds to nagios/sbin/statusmap. cgi: When you click the "Status Map" link on the left side of the Nagios Chinese running interface, servers such as apache and tomcat support CGI server software call the executable file statusmap. cgi to draw a network topology in the client area of the browser.

Statusmap. the function for drawing the device name of a node in c is void draw_text (char * buffer, int x, int y, int text_color), which is defined in this file, it calls a library function of GD --
GdImageString (map_image, gdFontSmall, x-(string_width/2), y-(2 * string_height), (unsigned char *) buffer, text_color); To draw the node device name.

Here we will briefly introduce the relationship between GD and other software and Nagios. Nagios processes images including drawing text. GD is required. In some versions of Linux, GD has been integrated, so you can directly install and use Nagios. The sequence of GD installation and related software packages is as follows ):
Gd: a software package for processing images, including drawing text;
Freetype: The software package used by the gd parsing font;
Libpng: The software package used by gd to parse png images;
Jpeg: The software package used by gd to parse jpeg images.

Example of installation method:

Installation Method
Install freetype
# Cd/data/software
# Tar xzvf freetype-2.1.5.tar.gz
# Cd freetype-2.1.5
#./Configure -- prefix =/usr/local/modules/freetype
# Make
# Make install

Install libpng
# Cd/data/software
# Tar xzvf libpng-1.2.5.tar.gz
# Cd libpng-1.2.5
# Cp scripts/makefile. std makefile \ do not use -- prefix to customize the installation directory, which affects gd installation.
# Make
# Make install

Install jpeg
# Mkdir/usr/local/modules 6
# Mkdir/usr/local/modules 6/bin
# Mkdir/usr/local/modules 6/lib
# Mkdir/usr/local/modules 6/include
# Mkdir/usr/local/modules 6/man
# Mkdir/usr/local/modules 6/man/man1
# Cd/data/software
# Tar xzvf restart src.v6b.tar.gz
#./Configure -- prefix =/usr/local/modules 6 -- enable-shared -- enable-static
# Make
# Make install

Install gd
# Cd/data/software
# Tar xzvf gd-2.0.33.tar.gz
#. /Configure -- prefix =/usr/local/modules/gd -- with-jpeg =/usr/local/modules 6 -- with-png -- with-zlib -- with-freetype =/ usr/local/modules/freetype
# Make
# Make install

Finally, when installing nagios #./configure step, add a set of parameters: -- with-gd-lib =/usr/local/modules/gd/lib

The original Nagios Chinese Version cannot draw Chinese strings, which is related to the GD Font Processing Method. GD has its own font file lattice format, ASC code ). The second parameter of gdImageString is the index of the GD font, and the fifth parameter is an ASC-encoded string. The GD Font does not support Chinese characters. Obviously, the well-known GD cannot only support its own font library. He uses the gdImageStringFT function to support the use of an external font to draw UTF-8 encoded strings, which contains Chinese support.

GdImageStringFT (gdImage * im, int * brect, int fg, char * fontlist, double ptsize, double angle, int x, int y, char * string ), the "FT" in the function name indicates freetype. This function supports parsing by calling the freetype package. ttf format ttf is the abbreviation of TrueType Font), as long as you find the location of the Chinese Character Library in Linux, as the fourth parameter to pass to this function, and ensure that char * string is UTF-8 encoded, you can draw Chinese strings smoothly. In my debugging environment, modify the following:
Original function:
GdImageString (map_image, gdFontSmall, x-(string_width/2), y-(2 * string_height), (unsigned char *) buffer, text_color );
After modification:
GdImageStringFT (map_image, & brect [0], text_color, "/usr/share/fonts/zh_CN/TrueType/gbsn00lp. ttf ", 10, 0.0, x-(string_width/2), y-(2 * string_height), buffer );
For detailed functions and descriptions of gdimagestringand gdimagestringft, see the description document index.html under the gdinstallation package)

Since Nagios reads the device name string from the configuration file and then draws it to the screen, if the configuration file itself is UTF-8 encoded, after the above modification, reload Nagios to display it smoothly. If the configuration file is not UTF-8, you can solve it in two ways:

First, convert the configuration file to UTF-8 encoding. In this case, you do not need to modify the source code again, but I do not agree with this method because the CGI of Nagios is written in C, while C is encoded in ASC, nagios does not rely on third-party databases, but relies on reading and writing a large number of configuration files and log files created by itself. Many string processing functions based on ASC encoding are used, although they are all in English, the English ASC encoding is exactly the same as UTF-8, But if you convert all Nagios-related files into UTF-8 encoding, it may cause some potential problems.

Type 2: Add a string encoding conversion function before gdImageStringFT to convert the read non-UTF-8 encoding string buffer into UTF-8 encoding and then pass it to gdImageStringFT for processing. There are a lot of resources on the Internet for such string conversion functions, which are not detailed here.

  1. Free SMS prompt configuration in Nagios Feixin linux
  2. Network Management: difficulties in Nagios Configuration
  3. Implementation of the Nagios network management module in Linux
  4. O & M monitoring Nagios serialization 3: deploying and configuring the Nagios Service
  5. O & M monitoring Nagios serialization 2: deploying an apache server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.