Nagios Group Plot Code implementation explained [1]

Source: Internet
Author: User

I. BACKGROUND

in view of the service grouping and image rendering function of Zabbix and cacti, the company leaders take the business maximization and stability as the goal orientation, and put forward the function of "monitoring system according to the service group map real-time display" in operation and maintenance department, which belongs to the Technical support Department of the company. , in the face of reasonable demand, can only be Yes.

Second, demand

Real-time display of monitoring system by service group diagram

Third, the SOFTWARE environment

[Email protected] ~]# cat/etc/redhat-release

CentOS Release 6.7 (Final)

[Email protected] ~]# uname-r

2.6.32-573.el6.x86_64

Lamp The software version of the environment and Nagios infrastructure is as follows:

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M02/8C/C6/wKiom1h3Tnnix0A4AABo9eP3-Eo391.png-wh_500x0-wm_ 3-wmp_4-s_1392348390.png "title=" Nagios Basic Environment software version "alt=" Wkiom1h3tnnix0a4aabo9ep3-eo391.png-wh_50 "/>

Figure 1 software version for the Nagios infrastructure

Iv. Demand Analysis and implementation

4.1 grouping function

the monitoring system we are using is Nagios, and it iswell known thatNagios defaults to the hosts and servers grouping functions, such as:

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/8C/C3/wKioL1h3TqyCIiBoAAAYTagn8PY642.png-wh_500x0-wm_ 3-wmp_4-s_3151465377.png "title=" nagios default grouping feature "alt=" Wkiol1h3tqyciiboaaaytagn8py642.png-wh_50 "/>

Figure 2 nagios default grouping feature

the group menu you see here is slightly different from the default version of nagios4.1.1, which is the style we have modified, which is interesting to try.

Host Group 3 is shown.

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/8C/C6/wKiom1h3TtvjvMxQAAEczCwzPGY157.png-wh_500x0-wm_ 3-wmp_4-s_4020091558.png "title=" Nagios host Group "alt=" Wkiom1h3ttvjvmxqaaeczcwzpgy157.png-wh_50 "/>

Figure 3 Nagios host grouping

The grouping we see in Figure 3 is one more column (choice) than before the modification, yes, how this column is added is what we will be explaining in detail next.

The Nagios Host Group page and the Service Group page are controlled by the status.cgi page, so we want to add the selection column, we must modify the Nagios source package, find the status.c file, Modify and recompile, and then overwrite the existing status.cgi.

4.1.1 Modify ngios4.1.1 Source Package

[[email protected] nagios-4.1.1]# ls CGI/STATUS.C

Cgi/status.c

[email protected] nagios-4.1.1]# VIMCGI/STATUS.C +3598 # Modify 3598 the behavior is as follows

/*choice Add by Xuekun 2016-12-23*/

printf ("<thclass= ' status ' >choice</th>"); /* This column is a new addition, check box column * /

printf ("<thclass= ' status ' >Host</th><th>Status</th>");

printf ("<th>services</th><thclass= ' status ' >actions</th>\n");

[[Email protected]]# vim cgi/status.c +3628 # check box Select all Code, Service drop-down menu code

/*choice all Begin by Xuekun 2016-12-23 */

printf ("<tr>\n");

printf ("<td>\n");

printf ("<input type=\" checkbox\ "id=\" check_%s\ "name=\" all_%s\ "onclick=\" Check_all (this, '%s ') \ "Class=\" Chec

Kbox\ "/>\n", Hstgrp->group_name,hstgrp->group_name, Hstgrp->group_name);

printf ("</td>\n");

printf ("<td>\n");

printf ("<select name= ' groupsrv ' >\n");

printf ("<option value= ' current_load ' selected= ' >load</option>\n");

printf ("<optionvalue= ' disk_partition ' >disk</option>\n");

printf ("<option value= ' PING ' >ping</option>\n");

printf ("<optionvalue= ' Iostat ' >iostat</option>\n");

printf ("<optionvalue= ' check_traffic ' >traffic</option>\n");

printf ("<optionvalue= ' Check_tcp_stat ' >tcp_stat</option></select>\n");

printf ("</td>\n");

printf ("<td><input type= ' submit ' value= ' View '/></td>\n");

printf ("<td></td>\n");

printf ("<td></td>\n");

printf ("</tr>\n");

/*choice all Begin by Xuekun 2016-12-23 */

the above two code additions, mainly solves the new check box column and the Service drop-down menu question, next we also want through the jquery to implement the check box the full selection, the code implementation in 544 Line's document_footer function, follow the web design rules, put JS at the end of the page, improve page loading speed.

void Document_footer (void) {

if (embedded = = TRUE)

Return

/* Include user SSI footer */

Include_ssi_files (status_cgi, Ssi_footer);

printf ("<script type=\" text/javascript\ ">\n");

printf ("Function check_all (Obj,flag) \ n");

printf ("{var is_checked =obj.checked;\n");

printf ("var checkboxs = $ (\" input[flag= ' \ "+ flag+\" ']\ "); \ n");

printf ("Console.log (is_checked); \ n");

printf ("Checkboxs.each" (function () {\ n ");

printf ("var Cur_box = $ (this); \ n");

printf ("Cur_box.prop (\" checked\ ", is_checked); \ n");

printf ("});} </script>\n ");

printf ("</body>\n");

printf ("

Return

}

The above code modification is complete, the next thing to do is recompile Nagios, the command is as follows

[[email protected] nagios-4.1.1]# make all # Execution make all Command Recompile Nagios

Nagios compiles, we want to replace the compiled status.cgi with the status.cgi of the/usr/local/nagios/sbin/directory , Remember to stop Nagios before you replace it with the following:

[email protected] nagios-4.1.1]#/etc/init.d/nagiosstop # Stop Nagios

[[Email protected]]# cp/usr/local/nagios/sbin/status.cgi/home/xuekun/status.cgi_bak # back up Legacy files

[email protected] nagios-4.1.1]#/bin/cpcgi/status.cgi/usr/local/nagios/sbin/status.cgi # Replace the original status.cgi

after executing the above command, F5 Refresh the Nagios access page, then click on the "hostgroup" link to see if there are any new discoveries!!!

Good luck!

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/8C/C3/wKioL1h3TxTQ7B31AAEczCwzPGY479.png-wh_500x0-wm_ 3-wmp_4-s_1683530318.png "title=" Nagios host Group "alt=" Wkiol1h3txtq7b31aaeczcwzpgy479.png-wh_50 "/>

This article is from the "Beijing Open source people Linux operation and Maintenance" blog, please be sure to keep this source http://bdkyr.blog.51cto.com/7961566/1891535

Nagios Group Plot Code implementation explained [1]

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.