[host] [port]"
14 | exit 1
15 | }
16 |
17 | if [ "x$1" = "xdiscovery" ]; then
18 |
19 | COUNT=`echo "$MYSQL_PORTS" | wc -w`
20 | INDEX=0
21 | echo '{"data":['
22 | for MYSQL_PORT in $MYSQL_PORTS; do
23 | echo -n '{"{#MYSQL_PORT}":"'$MYSQL_PORT'"}'
24 | INDEX=`expr $INDEX + 1`
25 | if [ $INDEX -lt $COUNT ]; then
26 | echo ','
27 | fi
28 | done
29 | echo ']}'
30 |
31 | elif [ "x$1" = "xcollector" ]; then
32 |
33 | if [ -z $2 ] || [ -z $3 ]; then
34 | usage
35 | fi
36 |
37 | HOST_HOST=$2
38 | MYSQL_PORT=$3
39 |
40 | EXTENDED_STATUS=`mysqladmin -u$MYSQL_USERNAME -p$MYSQL_PASSWORD -h127.0.0.1 -P$MYSQL_PORT extended-status`
41 |
42 | DATA=""
43 | for MYSQL_VARIABLE in $MYSQL_VARIABLES; do
44 | VALUE=`echo "$EXTENDED_STATUS" | grep -w "$MYSQL_VARIABLE" | awk '{print $4}'`
45 | if [ -n "$VALUE" ]; then
46 | DATA=$DATA"- mysql-v2.check[$MYSQL_PORT,$MYSQL_VARIABLE] $VALUE\n"
47 | fi
48 | done
49 |
50 | REPLICATION_DELAY=`mysql -u$MYSQL_USERNAME -p$MYSQL_PASSWORD -h127.0.0.1 -P$MYSQL_PORT -Dheartbeat_db -e "SELECT UNIX_TIMESTAMP() - UNIX_TIMESTAMP(ts) FROM heartbeat ORDER BY id DESC LIMIT 1" | sed '1d'`
51 |
52 | if [ -n "$REPLICATION_DELAY" ]; then
53 | DATA=$DATA"- mysql-v2.check[$MYSQL_PORT,Replication_delay] $REPLICATION_DELAY\n"
54 | fi
55 |
56 | if [ -n "$DATA" ]; then
57 | echo -e "$DATA" | $ZABBIX_BIN -s "$HOST_HOST" -i- >/dev/null 2>&1
58 | echo 1
59 | else
60 | echo 0
61 | fi
62 |
63 | else
64 | usage
65 | fi
66 |
--------------------------------------------------------------------------------
/mysql/mysql-params.conf:
--------------------------------------------------------------------------------
1 | UserParameter=mysql-v2.discovery,/usr/local/zabbix-agent-ops/bin/mysql-check-v2.sh discovery
2 | UserParameter=mysql-v2.collector[*],/usr/local/zabbix-agent-ops/bin/mysql-check-v2.sh collector "$1" $2
3 |
--------------------------------------------------------------------------------
/mysql/mysql-template.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 2.0
4 | 2013-05-03T13:52:15Z
5 |
6 |
7 | Templates
8 |
9 |
10 |
11 |
12 | Template MySQL v2
13 | Template MySQL v2
14 |
15 |
16 | Templates
17 |
18 |
19 |
20 |
21 | MySQL
22 |
23 |
24 |
25 |
26 |
27 | MySQL Instance
28 | 0
29 |
30 |
31 | mysql-v2.discovery
32 | 30
33 | 0
34 |
35 |
36 | 0
37 |
38 |
39 |
40 |
41 |
42 | 0
43 |
44 |
45 |
46 |
47 |
48 | :
49 | 30
50 |
51 |
52 |
53 | $1 $2
54 | 2
55 |
56 | 0
57 |
58 | mysql-v2.check[{#MYSQL_PORT},Threads_connected]
59 | 0
60 | 90
61 | 365
62 | 0
63 | 3
64 |
65 |
66 | 0
67 |
68 | 0
69 |
70 |
71 | 1
72 |
73 |
74 |
75 | 0
76 | 0
77 |
78 |
79 |
80 |
81 |
82 |
83 | 0
84 |
85 |
86 | MySQL
87 |
88 |
89 |
90 |
91 |
92 | $1 $2
93 | 2
94 |
95 | 0
96 |
97 | mysql-v2.check[{#MYSQL_PORT},Slow_queries]
98 | 0
99 | 90
100 | 365
101 | 0
102 | 3
103 |
104 |
105 | 2
106 |
107 | 0
108 |
109 |
110 | 1
111 |
112 |
113 |
114 | 0
115 | 0
116 |
117 |
118 |
119 |
120 |
121 |
122 | 0
123 |
124 |
125 | MySQL
126 |
127 |
128 |
129 |
130 |
131 | $1 $2
132 | 2
133 |
134 | 0
135 |
136 | mysql-v2.check[{#MYSQL_PORT},Threads_running]
137 | 0
138 | 90
139 | 365
140 | 0
141 | 3
142 |
143 |
144 | 0
145 |
146 | 0
147 |
148 |
149 | 1
150 |
151 |
152 |
153 | 0
154 | 0
155 |
156 |
157 |
158 |
159 |
160 |
161 | 0
162 |
163 |
164 | MySQL
165 |
166 |
167 |
168 |
169 |
170 | $1 $2
171 | 2
172 |
173 | 0
174 |
175 | mysql-v2.check[{#MYSQL_PORT},Replication_delay]
176 | 0
177 | 90
178 | 365
179 | 0
180 | 3
181 |
182 |
183 | 0
184 |
185 | 0
186 |
187 |
188 | 1
189 |
190 |
191 |
192 | 0
193 | 0
194 |
195 |
196 |
197 |
198 |
199 |
200 | 0
201 |
202 |
203 | MySQL
204 |
205 |
206 |
207 |
208 |
209 | $1 $2
210 | 2
211 |
212 | 0
213 |
214 | mysql-v2.check[{#MYSQL_PORT},Com_select]
215 | 0
216 | 90
217 | 365
218 | 0
219 | 3
220 |
221 |
222 | 1
223 |
224 | 0
225 |
226 |
227 | 1
228 |
229 |
230 |
231 | 0
232 | 0
233 |
234 |
235 |
236 |
237 |
238 |
239 | 0
240 |
241 |
242 | MySQL
243 |
244 |
245 |
246 |
247 |
248 | $1 $2
249 | 15
250 |
251 | 0
252 |
253 | mysql-v2.check[{#MYSQL_PORT},Com_write_total]
254 | 60
255 | 90
256 | 365
257 | 0
258 | 3
259 |
260 |
261 | 0
262 |
263 | 0
264 |
265 |
266 | 1
267 |
268 | last("mysql-v2.check[{#MYSQL_PORT},Com_insert]")
269 | + last("mysql-v2.check[{#MYSQL_PORT},Com_update]")
270 | + last("mysql-v2.check[{#MYSQL_PORT},Com_delete]")
271 | + last("mysql-v2.check[{#MYSQL_PORT},Com_replace]")
272 |
273 | 0
274 | 0
275 |
276 |
277 |
278 |
279 |
280 |
281 | 0
282 |
283 |
284 | MySQL
285 |
286 |
287 |
288 |
289 |
290 | $1 $2
291 | 2
292 |
293 | 0
294 |
295 | mysql-v2.check[{#MYSQL_PORT},Aborted_clients]
296 | 0
297 | 90
298 | 365
299 | 0
300 | 3
301 |
302 |
303 | 2
304 |
305 | 0
306 |
307 |
308 | 1
309 |
310 |
311 |
312 | 0
313 | 0
314 |
315 |
316 |
317 |
318 |
319 |
320 | 0
321 |
322 |
323 | MySQL
324 |
325 |
326 |
327 |
328 |
329 | $1 $2
330 | 2
331 |
332 | 0
333 |
334 | mysql-v2.check[{#MYSQL_PORT},Com_delete]
335 | 0
336 | 90
337 | 365
338 | 0
339 | 3
340 |
341 |
342 | 1
343 |
344 | 0
345 |
346 |
347 | 1
348 |
349 |
350 |
351 | 0
352 | 0
353 |
354 |
355 |
356 |
357 |
358 |
359 | 0
360 |
361 |
362 | MySQL
363 |
364 |
365 |
366 |
367 |
368 | $1 $2
369 | 2
370 |
371 | 0
372 |
373 | mysql-v2.check[{#MYSQL_PORT},Com_insert]
374 | 0
375 | 90
376 | 365
377 | 0
378 | 3
379 |
380 |
381 | 1
382 |
383 | 0
384 |
385 |
386 | 1
387 |
388 |
389 |
390 | 0
391 | 0
392 |
393 |
394 |
395 |
396 |
397 |
398 | 0
399 |
400 |
401 | MySQL
402 |
403 |
404 |
405 |
406 |
407 | $1 $2
408 | 2
409 |
410 | 0
411 |
412 | mysql-v2.check[{#MYSQL_PORT},Aborted_connects]
413 | 0
414 | 90
415 | 365
416 | 0
417 | 3
418 |
419 |
420 | 2
421 |
422 | 0
423 |
424 |
425 | 1
426 |
427 |
428 |
429 | 0
430 | 0
431 |
432 |
433 |
434 |
435 |
436 |
437 | 0
438 |
439 |
440 | MySQL
441 |
442 |
443 |
444 |
445 |
446 | $1 $2
447 | 2
448 |
449 | 0
450 |
451 | mysql-v2.check[{#MYSQL_PORT},Com_replace]
452 | 0
453 | 90
454 | 365
455 | 0
456 | 3
457 |
458 |
459 | 1
460 |
461 | 0
462 |
463 |
464 | 1
465 |
466 |
467 |
468 | 0
469 | 0
470 |
471 |
472 |
473 |
474 |
475 |
476 | 0
477 |
478 |
479 | MySQL
480 |
481 |
482 |
483 |
484 |
485 | $1 $2
486 | 2
487 |
488 | 0
489 |
490 | mysql-v2.check[{#MYSQL_PORT},Connections]
491 | 0
492 | 90
493 | 365
494 | 0
495 | 3
496 |
497 |
498 | 1
499 |
500 | 0
501 |
502 |
503 | 1
504 |
505 |
506 |
507 | 0
508 | 0
509 |
510 |
511 |
512 |
513 |
514 |
515 | 0
516 |
517 |
518 | MySQL
519 |
520 |
521 |
522 |
523 |
524 | $1 $2
525 | 2
526 |
527 | 0
528 |
529 | mysql-v2.check[{#MYSQL_PORT},Com_update]
530 | 0
531 | 90
532 | 365
533 | 0
534 | 3
535 |
536 |
537 | 1
538 |
539 | 0
540 |
541 |
542 | 1
543 |
544 |
545 |
546 | 0
547 | 0
548 |
549 |
550 |
551 |
552 |
553 |
554 | 0
555 |
556 |
557 | MySQL
558 |
559 |
560 |
561 |
562 |
563 | $2 Collector
564 | 0
565 |
566 | 0
567 |
568 | mysql-v2.collector[{HOST.HOST},{#MYSQL_PORT}]
569 | 60
570 | 90
571 | 365
572 | 0
573 | 3
574 |
575 |
576 | 0
577 |
578 | 0
579 |
580 |
581 | 1
582 |
583 |
584 |
585 | 3
586 | 0
587 |
588 |
589 |
590 |
591 |
592 |
593 | 0
594 |
595 |
596 | MySQL
597 |
598 |
599 |
600 | Service state
601 |
602 |
603 |
604 |
605 |
606 |
607 | MySQL {#MYSQL_PORT} Connections
608 | 900
609 | 200
610 | 0.0000
611 | 100.0000
612 | 1
613 | 1
614 | 0
615 | 1
616 | 0
617 | 0.0000
618 | 0.0000
619 | 0
620 | 0
621 | 0
622 | 0
623 |
624 |
625 | 1
626 | 0
627 | FF3333
628 | 0
629 | 2
630 | 0
631 | -
632 | Template MySQL v2
633 | mysql-v2.check[{#MYSQL_PORT},Aborted_clients]
634 |
635 |
636 |
637 | 2
638 | 0
639 | 6666FF
640 | 0
641 | 2
642 | 0
643 | -
644 | Template MySQL v2
645 | mysql-v2.check[{#MYSQL_PORT},Aborted_connects]
646 |
647 |
648 |
649 | 0
650 | 0
651 | 00EE00
652 | 0
653 | 2
654 | 0
655 | -
656 | Template MySQL v2
657 | mysql-v2.check[{#MYSQL_PORT},Connections]
658 |
659 |
660 |
661 |
662 |
663 | MySQL {#MYSQL_PORT} Read / Write
664 | 900
665 | 200
666 | 0.0000
667 | 100.0000
668 | 1
669 | 1
670 | 0
671 | 1
672 | 0
673 | 0.0000
674 | 0.0000
675 | 0
676 | 0
677 | 0
678 | 0
679 |
680 |
681 | 0
682 | 0
683 | 00CC00
684 | 0
685 | 2
686 | 0
687 | -
688 | Template MySQL v2
689 | mysql-v2.check[{#MYSQL_PORT},Com_select]
690 |
691 |
692 |
693 | 1
694 | 0
695 | DD0000
696 | 0
697 | 2
698 | 0
699 | -
700 | Template MySQL v2
701 | mysql-v2.check[{#MYSQL_PORT},Com_write_total]
702 |
703 |
704 |
705 |
706 |
707 | MySQL {#MYSQL_PORT} Replication Delay
708 | 900
709 | 200
710 | 0.0000
711 | 100.0000
712 | 1
713 | 1
714 | 0
715 | 1
716 | 0
717 | 0.0000
718 | 0.0000
719 | 0
720 | 0
721 | 0
722 | 0
723 |
724 |
725 | 0
726 | 0
727 | 0000EE
728 | 0
729 | 2
730 | 0
731 | -
732 | Template MySQL v2
733 | mysql-v2.check[{#MYSQL_PORT},Replication_delay]
734 |
735 |
736 |
737 |
738 |
739 | MySQL {#MYSQL_PORT} Slow Queries
740 | 900
741 | 200
742 | 0.0000
743 | 100.0000
744 | 1
745 | 1
746 | 0
747 | 1
748 | 0
749 | 0.0000
750 | 0.0000
751 | 0
752 | 0
753 | 0
754 | 0
755 |
756 |
757 | 0
758 | 0
759 | 0000EE
760 | 0
761 | 2
762 | 0
763 | -
764 | Template MySQL v2
765 | mysql-v2.check[{#MYSQL_PORT},Slow_queries]
766 |
767 |
768 |
769 |
770 |
771 | MySQL {#MYSQL_PORT} Threads
772 | 900
773 | 200
774 | 0.0000
775 | 100.0000
776 | 1
777 | 1
778 | 0
779 | 1
780 | 0
781 | 0.0000
782 | 0.0000
783 | 0
784 | 0
785 | 0
786 | 0
787 |
788 |
789 | 0
790 | 0
791 | 00DD00
792 | 0
793 | 2
794 | 0
795 | -
796 | Template MySQL v2
797 | mysql-v2.check[{#MYSQL_PORT},Threads_connected]
798 |
799 |
800 |
801 | 1
802 | 0
803 | EE0000
804 | 0
805 | 2
806 | 0
807 | -
808 | Template MySQL v2
809 | mysql-v2.check[{#MYSQL_PORT},Threads_running]
810 |
811 |
812 |
813 |
814 |
815 |
816 |
817 |
818 |
819 |
820 |
821 |
822 |
823 |
--------------------------------------------------------------------------------
/nginx/README.md:
--------------------------------------------------------------------------------
1 | Template Nginx
2 | ==============
3 |
4 | Show Nginx status in Zabbix.
5 |
6 | INSTALL
7 | -------
8 |
9 | Assume the Zabbix agent is installed in /zabbix-agent/ directory.
10 |
11 | ### Nginx HttpStubStatusModule
12 |
13 | Nginx needs to be built with HttpStubStatusModule, i.e. --with-http_stub_status_module. You can use `nginx -V` to check whether the current binary includes this module.
14 |
15 | More information could be found in this [Wiki][1]
16 |
17 | ### Add Configuration
18 |
19 | Add the following into Nginx configuration:
20 |
21 |
22 | server {
23 | listen 10051;
24 | location /nginx_status {
25 | stub_status on;
26 | access_log off;
27 | allow 127.0.0.1;
28 | deny all;
29 | }
30 | }
31 |
32 |
33 | Reload Nginx, and use `curl http://127.0.0.1:10051/nginx_status` to get the statistics.
34 |
35 | ### Add User Parameters
36 |
37 | Copy nginx-params.conf to /usr/local/zabbix/conf/zabbix_agentd/. Restart Zabbix agent.
38 | Add line "Include=/usr/local/zabbix/conf/zabbix_agentd/*.conf" in /usr/local/zabbix/conf/zabbix_agentd.conf
39 |
40 | ### Import Template
41 |
42 | Import nginx-template.xml, and link it to a host. Set the host macro {$NGINX_STATUS_URL} if needed.
43 |
44 |
45 | CREDITS
46 | -------
47 |
48 | The scripts are form http://github.com/zbal/zabbix.
49 |
50 | [1]: http://wiki.nginx.org/HttpStubStatusModule
51 |
--------------------------------------------------------------------------------
/nginx/nginx-check.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | ##################################
3 | # Zabbix monitoring script
4 | #
5 | # nginx:
6 | # - anything available via nginx stub-status module
7 | #
8 | ##################################
9 | # Contact:
10 | # vincent.viallet@gmail.com
11 | ##################################
12 | # ChangeLog:
13 | # 20100922 VV initial creation
14 | ##################################
15 |
16 | # Zabbix requested parameter
17 | ZBX_REQ_DATA="$1"
18 | ZBX_REQ_DATA_URL="$2"
19 |
20 | # Nginx defaults
21 | NGINX_STATUS_DEFAULT_URL="http://localhost:80/nginx_status"
22 | WGET_BIN="/usr/bin/wget"
23 |
24 | #
25 | # Error handling:
26 | # - need to be displayable in Zabbix (avoid NOT_SUPPORTED)
27 | # - items need to be of type "float" (allow negative + float)
28 | #
29 | ERROR_NO_ACCESS_FILE="-0.9900"
30 | ERROR_NO_ACCESS="-0.9901"
31 | ERROR_WRONG_PARAM="-0.9902"
32 | ERROR_DATA="-0.9903" # either can not connect / bad host / bad port
33 |
34 | # Handle host and port if non-default
35 | if [ ! -z "$ZBX_REQ_DATA_URL" ]; then
36 | URL="$ZBX_REQ_DATA_URL"
37 | else
38 | URL="$NGINX_STATUS_DEFAULT_URL"
39 | fi
40 |
41 | # save the nginx stats in a variable for future parsing
42 | NGINX_STATS=$($WGET_BIN -q $URL -O - 2> /dev/null)
43 |
44 | # error during retrieve
45 | if [ $? -ne 0 -o -z "$NGINX_STATS" ]; then
46 | echo $ERROR_DATA
47 | exit 1
48 | fi
49 |
50 | #
51 | # Extract data from nginx stats
52 | #
53 | case $ZBX_REQ_DATA in
54 | active_connections) echo "$NGINX_STATS" | head -1 | cut -f3 -d' ';;
55 | accepted_connections) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f2 -d' ';;
56 | handled_connections) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f3 -d' ';;
57 | handled_requests) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f4 -d' ';;
58 | reading) echo "$NGINX_STATS" | tail -1 | cut -f2 -d' ';;
59 | writing) echo "$NGINX_STATS" | tail -1 | cut -f4 -d' ';;
60 | waiting) echo "$NGINX_STATS" | tail -1 | cut -f6 -d' ';;
61 | *) echo $ERROR_WRONG_PARAM; exit 1;;
62 | esac
63 |
64 | exit 0
65 |
--------------------------------------------------------------------------------
/nginx/nginx-params.conf:
--------------------------------------------------------------------------------
1 | UserParameter=nginx[*],/usr/local/zabbix/bin/nginx-check.sh "$1" "$2"
2 |
--------------------------------------------------------------------------------
/nginx/nginx-template.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 2.0
4 | 2013-03-26T04:17:58Z
5 |
6 |
7 | Templates
8 |
9 |
10 |
11 |
12 | Template_Nginx
13 | Template_Nginx
14 |
15 |
16 | Templates
17 |
18 |
19 |
20 |
21 | Nginx
22 |
23 |
24 |
25 | -
26 | Nginx $1
27 | 0
28 |
29 | 0
30 |
31 | nginx[waiting,{$NGINX_STATUS_URL}]
32 | 60
33 | 30
34 | 365
35 | 0
36 | 0
37 |
38 |
39 | 0
40 |
41 | 0
42 |
43 |
44 | 1
45 |
46 |
47 |
48 | 0
49 | 0
50 |
51 |
52 |
53 |
54 |
55 |
56 | 0
57 |
58 |
59 | Nginx
60 |
61 |
62 |
63 |
64 | -
65 | Nginx $1
66 | 0
67 |
68 | 0
69 |
70 | nginx[writing,{$NGINX_STATUS_URL}]
71 | 60
72 | 30
73 | 365
74 | 0
75 | 0
76 |
77 |
78 | 0
79 |
80 | 0
81 |
82 |
83 | 1
84 |
85 |
86 |
87 | 0
88 | 0
89 |
90 |
91 |
92 |
93 |
94 |
95 | 0
96 |
97 |
98 | Nginx
99 |
100 |
101 |
102 |
103 | -
104 | Nginx $1
105 | 0
106 |
107 | 0
108 |
109 | nginx[active_connections,{$NGINX_STATUS_URL}]
110 | 60
111 | 30
112 | 365
113 | 0
114 | 0
115 |
116 |
117 | 0
118 |
119 | 0
120 |
121 |
122 | 1
123 |
124 |
125 |
126 | 0
127 | 0
128 |
129 |
130 |
131 |
132 |
133 |
134 | 0
135 |
136 |
137 | Nginx
138 |
139 |
140 |
141 |
142 | -
143 | Nginx $1
144 | 0
145 |
146 | 0
147 |
148 | nginx[reading,{$NGINX_STATUS_URL}]
149 | 60
150 | 30
151 | 365
152 | 0
153 | 0
154 |
155 |
156 | 0
157 |
158 | 0
159 |
160 |
161 | 1
162 |
163 |
164 |
165 | 0
166 | 0
167 |
168 |
169 |
170 |
171 |
172 |
173 | 0
174 |
175 |
176 | Nginx
177 |
178 |
179 |
180 |
181 | -
182 | Nginx $1/sec
183 | 0
184 |
185 | 0
186 |
187 | nginx[handled_requests,{$NGINX_STATUS_URL}]
188 | 60
189 | 30
190 | 365
191 | 0
192 | 0
193 |
194 |
195 | 1
196 |
197 | 0
198 |
199 |
200 | 1
201 |
202 |
203 |
204 | 0
205 | 0
206 |
207 |
208 |
209 |
210 |
211 |
212 | 0
213 |
214 |
215 | Nginx
216 |
217 |
218 |
219 |
220 | -
221 | Nginx $1/sec
222 | 0
223 |
224 | 0
225 |
226 | nginx[accepted_connections,{$NGINX_STATUS_URL}]
227 | 60
228 | 30
229 | 365
230 | 0
231 | 0
232 |
233 |
234 | 1
235 |
236 | 0
237 |
238 |
239 | 1
240 |
241 |
242 |
243 | 0
244 | 0
245 |
246 |
247 |
248 |
249 |
250 |
251 | 0
252 |
253 |
254 | Nginx
255 |
256 |
257 |
258 |
259 | -
260 | Nginx $1/sec
261 | 0
262 |
263 | 0
264 |
265 | nginx[handled_connections,{$NGINX_STATUS_URL}]
266 | 60
267 | 30
268 | 365
269 | 0
270 | 0
271 |
272 |
273 | 1
274 |
275 | 0
276 |
277 |
278 | 1
279 |
280 |
281 |
282 | 0
283 | 0
284 |
285 |
286 |
287 |
288 |
289 |
290 | 0
291 |
292 |
293 | Nginx
294 |
295 |
296 |
297 |
298 | -
299 | Number of $1 process
300 | 0
301 | public
302 | 0
303 | interfaces.ifTable.ifEntry.ifInOctets.1
304 | proc.num[nginx]
305 | 300
306 | 30
307 | 365
308 | 0
309 | 3
310 |
311 |
312 | 0
313 |
314 | 0
315 |
316 |
317 | 1
318 |
319 |
320 |
321 | 0
322 | 0
323 |
324 |
325 |
326 |
327 |
328 |
329 | 0
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 | {$NGINX_STATUS_URL}
338 | http://127.0.0.1:10061/nginx_status
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 | {Template_Nginx:proc.num[nginx].last(0)}=0
348 | Nginx is not running on {HOSTNAME}
349 |
350 | 0
351 | 4
352 | Nginx is not running.
353 |
354 | It has been stopped / shutdown or has crashed.
355 | Check on the server for more details:
356 | - w / last
357 | - dmesg logs
358 | - /var/log/messages
359 | - nginx error logs
360 | 0
361 |
362 |
363 |
364 |
365 |
366 | Nginx - Connections and Requests status
367 | 900
368 | 200
369 | 0.0000
370 | 100.0000
371 | 0
372 | 0
373 | 0
374 | 1
375 | 0
376 | 0.0000
377 | 0.0000
378 | 1
379 | 0
380 | 0
381 | 0
382 |
383 |
384 | 0
385 | 1
386 | FF9999
387 | 0
388 | 4
389 | 0
390 | -
391 | Template_Nginx
392 | nginx[accepted_connections,{$NGINX_STATUS_URL}]
393 |
394 |
395 |
396 | 1
397 | 2
398 | 990000
399 | 0
400 | 4
401 | 0
402 | -
403 | Template_Nginx
404 | nginx[handled_connections,{$NGINX_STATUS_URL}]
405 |
406 |
407 |
408 | 2
409 | 0
410 | 009900
411 | 0
412 | 4
413 | 0
414 | -
415 | Template_Nginx
416 | nginx[handled_requests,{$NGINX_STATUS_URL}]
417 |
418 |
419 |
420 |
421 |
422 | Nginx - Threads status
423 | 900
424 | 200
425 | 0.0000
426 | 100.0000
427 | 0
428 | 0
429 | 1
430 | 1
431 | 0
432 | 0.0000
433 | 0.0000
434 | 1
435 | 0
436 | 0
437 | 0
438 |
439 |
440 | 0
441 | 1
442 | 990000
443 | 0
444 | 4
445 | 0
446 | -
447 | Template_Nginx
448 | nginx[writing,{$NGINX_STATUS_URL}]
449 |
450 |
451 |
452 | 1
453 | 1
454 | 999900
455 | 0
456 | 4
457 | 0
458 | -
459 | Template_Nginx
460 | nginx[reading,{$NGINX_STATUS_URL}]
461 |
462 |
463 |
464 | 2
465 | 1
466 | 009900
467 | 0
468 | 4
469 | 0
470 | -
471 | Template_Nginx
472 | nginx[waiting,{$NGINX_STATUS_URL}]
473 |
474 |
475 |
476 |
477 |
478 |
479 |
--------------------------------------------------------------------------------
/php-fpm/README.md:
--------------------------------------------------------------------------------
1 | Template php-fpm
2 | ================
3 |
4 | Show php-fpm statistics in Zabbix.
5 |
6 | INSTALL
7 | -------
8 |
9 | Assume the Zabbix agent is installed in /zabbix-agent/ directory.
10 |
11 | ### Configure php-fpm
12 |
13 | Open the php-fpm pool's configuration file, uncomment the 'pm.status=' directive:
14 |
15 | pm.status_path = /php-fpm_status
16 |
17 | Since php-fpm's statistics is collected by different pools, so you need to create corresponding hosts for them.
18 |
19 | ### Configure Nginx
20 |
21 | Add the following lines to Nginx configuration:
22 |
23 | ```
24 | server {
25 | listen 10061;
26 |
27 | location /php-fpm_status {
28 | fastcgi_pass 127.0.0.1:9000;
29 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
30 | include fastcgi_params;
31 | }
32 | }
33 | ```
34 |
35 | After restarting both php-fpm and nginx, try the following command to test:
36 |
37 | $ curl http://127.0.0.1:10061/php-fpm_status
38 |
39 | ### Add User Parameters
40 |
41 | Copy php-fpm-params.conf to /zabbix-agent/etc/zabbix_agentd.conf.d/. Restart Zabbix agent.
42 |
43 | ### Import Template
44 |
45 | Import php-fpm-template.xml, and link it to a host. Set the host macro {$PHP_FPM_STATUS_URL} if needed.
46 |
47 |
48 | CREDITS
49 | -------
50 |
51 | Some of the scripts are form http://github.com/zbal/zabbix.
52 |
53 |
--------------------------------------------------------------------------------
/php-fpm/php-fpm-check.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | ##################################
3 | # Zabbix monitoring script
4 | #
5 | # php-fpm:
6 | # - anything available via FPM status page
7 | #
8 | ##################################
9 | # Contact:
10 | # vincent.viallet@gmail.com
11 | ##################################
12 | # ChangeLog:
13 | # 20100922 VV initial creation
14 | ##################################
15 |
16 | # Zabbix requested parameter
17 | ZBX_REQ_DATA="$1"
18 | ZBX_REQ_DATA_URL="$2"
19 |
20 | # Nginx defaults
21 | NGINX_STATUS_DEFAULT_URL="http://localhost:80/php-fpm_status"
22 | WGET_BIN="/usr/bin/wget"
23 |
24 | #
25 | # Error handling:
26 | # - need to be displayable in Zabbix (avoid NOT_SUPPORTED)
27 | # - items need to be of type "float" (allow negative + float)
28 | #
29 | ERROR_NO_ACCESS_FILE="-0.9900"
30 | ERROR_NO_ACCESS="-0.9901"
31 | ERROR_WRONG_PARAM="-0.9902"
32 | ERROR_DATA="-0.9903" # either can not connect / bad host / bad port
33 |
34 | # Handle host and port if non-default
35 | if [ ! -z "$ZBX_REQ_DATA_URL" ]; then
36 | URL="$ZBX_REQ_DATA_URL"
37 | else
38 | URL="$NGINX_STATUS_DEFAULT_URL"
39 | fi
40 |
41 | # save the nginx stats in a variable for future parsing
42 | NGINX_STATS=$($WGET_BIN -q $URL -O - 2> /dev/null)
43 |
44 | # error during retrieve
45 | if [ $? -ne 0 -o -z "$NGINX_STATS" ]; then
46 | echo $ERROR_DATA
47 | exit 1
48 | fi
49 |
50 | #
51 | # Extract data from nginx stats
52 | #
53 | RESULT=$(echo "$NGINX_STATS" | awk 'match($0, "^'"$ZBX_REQ_DATA"':[[:space:]]+(.*)", a) { print a[1] }')
54 | if [ $? -ne 0 -o -z "$RESULT" ]; then
55 | echo $ERROR_WRONG_PARAM
56 | exit 1
57 | fi
58 |
59 | echo $RESULT
60 |
61 | exit 0
62 |
--------------------------------------------------------------------------------
/php-fpm/php-fpm-params.conf:
--------------------------------------------------------------------------------
1 | UserParameter=php-fpm[*],/usr/local/zabbix-agent-ops/bin/php-fpm-check.sh "$1" "$2"
2 |
--------------------------------------------------------------------------------
/php-fpm/php-fpm-template.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 2.0
4 | 2013-03-26T04:12:09Z
5 |
6 |
7 | Templates
8 |
9 |
10 |
11 |
12 | Template php-fpm
13 | Template php-fpm
14 |
15 |
16 | Templates
17 |
18 |
19 |
20 |
21 | php-fpm
22 |
23 |
24 |
25 | -
26 | $1
27 | 0
28 |
29 | 0
30 |
31 | php-fpm["total processes",{$PHP_FPM_STATUS_URL}]
32 | 60
33 | 90
34 | 365
35 | 0
36 | 3
37 |
38 |
39 | 0
40 |
41 | 0
42 |
43 |
44 | 1
45 |
46 |
47 |
48 | 0
49 | 0
50 |
51 |
52 |
53 |
54 |
55 |
56 | 0
57 |
58 |
59 | php-fpm
60 |
61 |
62 |
63 |
64 | -
65 | $1
66 | 0
67 |
68 | 0
69 |
70 | php-fpm["listen queue",{$PHP_FPM_STATUS_URL}]
71 | 60
72 | 90
73 | 365
74 | 0
75 | 3
76 |
77 |
78 | 0
79 |
80 | 0
81 |
82 |
83 | 1
84 |
85 |
86 |
87 | 0
88 | 0
89 |
90 |
91 |
92 |
93 |
94 |
95 | 0
96 |
97 |
98 | php-fpm
99 |
100 |
101 |
102 |
103 | -
104 | $1
105 | 0
106 |
107 | 0
108 |
109 | php-fpm["listen queue len",{$PHP_FPM_STATUS_URL}]
110 | 60
111 | 90
112 | 365
113 | 0
114 | 3
115 |
116 |
117 | 0
118 |
119 | 0
120 |
121 |
122 | 1
123 |
124 |
125 |
126 | 0
127 | 0
128 |
129 |
130 |
131 |
132 |
133 |
134 | 0
135 |
136 |
137 | php-fpm
138 |
139 |
140 |
141 |
142 | -
143 | $1
144 | 0
145 |
146 | 0
147 |
148 | php-fpm["active processes",{$PHP_FPM_STATUS_URL}]
149 | 60
150 | 90
151 | 365
152 | 0
153 | 3
154 |
155 |
156 | 0
157 |
158 | 0
159 |
160 |
161 | 1
162 |
163 |
164 |
165 | 0
166 | 0
167 |
168 |
169 |
170 |
171 |
172 |
173 | 0
174 |
175 |
176 | php-fpm
177 |
178 |
179 |
180 |
181 | -
182 | $1
183 | 0
184 |
185 | 0
186 |
187 | php-fpm["idle processes",{$PHP_FPM_STATUS_URL}]
188 | 60
189 | 90
190 | 365
191 | 0
192 | 3
193 |
194 |
195 | 0
196 |
197 | 0
198 |
199 |
200 | 1
201 |
202 |
203 |
204 | 0
205 | 0
206 |
207 |
208 |
209 |
210 |
211 |
212 | 0
213 |
214 |
215 | php-fpm
216 |
217 |
218 |
219 |
220 | -
221 | $1/sec
222 | 0
223 |
224 | 0
225 |
226 | php-fpm["accepted conn",{$PHP_FPM_STATUS_URL}]
227 | 60
228 | 90
229 | 365
230 | 0
231 | 3
232 |
233 |
234 | 1
235 |
236 | 0
237 |
238 |
239 | 1
240 |
241 |
242 |
243 | 0
244 | 0
245 |
246 |
247 |
248 |
249 |
250 |
251 | 0
252 |
253 |
254 | php-fpm
255 |
256 |
257 |
258 |
259 | -
260 | $1/sec
261 | 0
262 |
263 | 0
264 |
265 | php-fpm["slow requests",{$PHP_FPM_STATUS_URL}]
266 | 60
267 | 90
268 | 365
269 | 0
270 | 3
271 |
272 |
273 | 1
274 |
275 | 0
276 |
277 |
278 | 1
279 |
280 |
281 |
282 | 0
283 | 0
284 |
285 |
286 |
287 |
288 |
289 |
290 | 0
291 |
292 |
293 | php-fpm
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 | {$PHP_FPM_STATUS_URL}
303 | http://127.0.0.1:10061/php-fpm_status
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 | php-fpm Accepted Connections / sec
313 | 900
314 | 200
315 | 0.0000
316 | 100.0000
317 | 1
318 | 1
319 | 0
320 | 1
321 | 0
322 | 0.0000
323 | 0.0000
324 | 0
325 | 0
326 | 0
327 | 0
328 |
329 |
330 | 0
331 | 0
332 | C80000
333 | 0
334 | 2
335 | 0
336 | -
337 | Template php-fpm
338 | php-fpm["accepted conn",{$PHP_FPM_STATUS_URL}]
339 |
340 |
341 |
342 |
343 |
344 | php-fpm Listen Queue
345 | 900
346 | 200
347 | 0.0000
348 | 100.0000
349 | 1
350 | 1
351 | 0
352 | 1
353 | 0
354 | 0.0000
355 | 0.0000
356 | 0
357 | 0
358 | 0
359 | 0
360 |
361 |
362 | 0
363 | 0
364 | EE0000
365 | 0
366 | 2
367 | 0
368 | -
369 | Template php-fpm
370 | php-fpm["listen queue len",{$PHP_FPM_STATUS_URL}]
371 |
372 |
373 |
374 | 1
375 | 0
376 | 00EE00
377 | 0
378 | 2
379 | 0
380 | -
381 | Template php-fpm
382 | php-fpm["listen queue",{$PHP_FPM_STATUS_URL}]
383 |
384 |
385 |
386 |
387 |
388 | php-fpm Processes
389 | 900
390 | 200
391 | 0.0000
392 | 100.0000
393 | 1
394 | 1
395 | 0
396 | 1
397 | 0
398 | 0.0000
399 | 0.0000
400 | 0
401 | 0
402 | 0
403 | 0
404 |
405 |
406 | 0
407 | 0
408 | C80000
409 | 0
410 | 2
411 | 0
412 | -
413 | Template php-fpm
414 | php-fpm["total processes",{$PHP_FPM_STATUS_URL}]
415 |
416 |
417 |
418 | 1
419 | 0
420 | 00C800
421 | 0
422 | 2
423 | 0
424 | -
425 | Template php-fpm
426 | php-fpm["active processes",{$PHP_FPM_STATUS_URL}]
427 |
428 |
429 |
430 | 2
431 | 0
432 | 0000C8
433 | 0
434 | 2
435 | 0
436 | -
437 | Template php-fpm
438 | php-fpm["idle processes",{$PHP_FPM_STATUS_URL}]
439 |
440 |
441 |
442 |
443 |
444 | php-fpm Slow Requests / sec
445 | 900
446 | 200
447 | 0.0000
448 | 100.0000
449 | 1
450 | 1
451 | 0
452 | 1
453 | 0
454 | 0.0000
455 | 0.0000
456 | 0
457 | 0
458 | 0
459 | 0
460 |
461 |
462 | 0
463 | 0
464 | C80000
465 | 0
466 | 2
467 | 0
468 | -
469 | Template php-fpm
470 | php-fpm["slow requests",{$PHP_FPM_STATUS_URL}]
471 |
472 |
473 |
474 |
475 |
476 |
477 |
--------------------------------------------------------------------------------
/scripts/daily_report.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # -*- coding: utf-8 -*-
3 | import os
4 | import time
5 | import shutil
6 | import MySQLdb
7 | import smtplib
8 | import requests
9 | import datetime
10 |
11 | from email.MIMEText import MIMEText
12 | from email.MIMEImage import MIMEImage
13 | from email.MIMEMultipart import MIMEMultipart
14 |
15 |
16 | # based on zabbix 2.4.4
17 | ZABBIX_HOST = '127.0.0.1'
18 | ZABBIX_USER = 'Admin'
19 | ZABBIX_PWD = 'password'
20 |
21 | ZABBIX_DB_HOST = 'localhost'
22 | ZABBIX_DB_USER = 'zabbix'
23 | ZABBIX_DB_PWD = 'db_password'
24 | ZABBIX_DB_NAME = 'zabbix'
25 |
26 | GRAPH_PATH = '/tmp/zabbix_graph'
27 | GRAPH_PERIOD = 86400 # one day
28 |
29 | EMAIL_DOMAIN = '163.com'
30 | EMAIL_USERNAME = 'wuxianglong098'
31 | EMAIL_PASSWORD = 'email_password'
32 |
33 |
34 | def query_screens(screen_name):
35 | conn = MySQLdb.connect(host=ZABBIX_DB_HOST, user=ZABBIX_DB_USER, passwd=ZABBIX_DB_PWD,
36 | db=ZABBIX_DB_NAME, charset='utf8', connect_timeout=20)
37 | cur = conn.cursor()
38 | count = cur.execute("""
39 | select a.name, a.screenid, b.resourceid, b.width, b.height
40 | from screens a, screens_items as b
41 | where a.screenid=b.screenid and a.templateid<=>NULL and a.name='%s'
42 | order by a.screenid;
43 | """ % screen_name)
44 | if count == 0:
45 | result = 0
46 | else:
47 | result = cur.fetchall()
48 |
49 | cur.close()
50 | conn.close()
51 |
52 | return result
53 |
54 |
55 | def generate_graphs(screens):
56 | login_resp = requests.post('http://%s/index.php' % ZABBIX_HOST, data={
57 | 'name': ZABBIX_USER,
58 | 'password': ZABBIX_PWD,
59 | 'enter': 'Sign in',
60 | 'autologin': 1,
61 | })
62 | session_id = login_resp.cookies['zbx_sessionid']
63 |
64 | graphs = []
65 | for i, (screen_name, screen_id, graph_id, width, height) in enumerate(screens):
66 | params = {
67 | 'screenid': screen_id,
68 | 'graphid': graph_id,
69 | 'width': width * 2,
70 | 'height': height * 2,
71 | 'period': GRAPH_PERIOD,
72 | 'stime': datetime.datetime.utcnow().strftime('%Y%m%d%H%M%S'),
73 | }
74 | resp = requests.get('http://%s/chart2.php' % ZABBIX_HOST, params=params,
75 | cookies={'zbx_sessionid': session_id})
76 | file_name = '_'.join(map(str, screens[i][:3])).replace(' ', '_') + '.png'
77 | with open(os.path.join(GRAPH_PATH, file_name), 'wb') as fp:
78 | fp.write(resp.content)
79 | graphs.append(file_name)
80 |
81 | return graphs
82 |
83 |
84 | def send_mail(screen_name, graphs, to_list):
85 | me = 'Zabbix <%s@%s>' % (EMAIL_USERNAME, EMAIL_DOMAIN)
86 |
87 | def _create_msg():
88 | msg = MIMEMultipart('related')
89 | msg['Subject'] = 'Zabbix Screen Report: %s' % screen_name
90 | msg['From'] = me
91 | msg['To'] = ';'.join(to_list)
92 | msg.preamble = 'This is a multi-part message in MIME format.'
93 |
94 | contents = "Screen %s
" % screen_name
95 | contents += ""
96 | for g_name in graphs:
97 | with open(os.path.join(GRAPH_PATH, g_name), 'rb') as fp:
98 | msg_image = MIMEImage(fp.read())
99 | msg_image.add_header('Content-ID', "<%s>" % g_name)
100 | msg.attach(msg_image)
101 |
102 | contents += ''
103 | contents += " |
" % g_name
104 | contents += "
"
105 |
106 | msg_text = MIMEText(contents, 'html')
107 | msg_alternative = MIMEMultipart('alternative')
108 | msg_alternative.attach(msg_text)
109 | msg.attach(msg_alternative)
110 |
111 | return msg
112 |
113 | try:
114 | server = smtplib.SMTP()
115 | server.connect('smtp.%s' % EMAIL_DOMAIN)
116 | server.login('%s@%s' % (EMAIL_USERNAME, EMAIL_DOMAIN), EMAIL_PASSWORD)
117 | server.sendmail(me, to_list, _create_msg().as_string())
118 | server.close()
119 | print 'send mail Ok!'
120 | except Exception, e:
121 | print e
122 |
123 |
124 | if __name__ == '__main__':
125 | # remove old dirs
126 | if os.path.exists(GRAPH_PATH):
127 | shutil.rmtree(GRAPH_PATH)
128 | os.makedirs(GRAPH_PATH)
129 |
130 | for srn_name in (u'Zabbix server', u'Nginx Connections'):
131 | # get screens
132 | all_screens = query_screens(srn_name)
133 | print all_screens
134 |
135 | # generate graphs
136 | graphs = generate_graphs(all_screens)
137 |
138 | send_mail(srn_name, graphs, ['wuxianglong098@163.com'])
139 |
--------------------------------------------------------------------------------
/scripts/install_zabbix_agent.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # -*- coding: utf-8 -*-
3 | import time
4 | import Queue
5 | import socket
6 | import paramiko
7 | import threading
8 |
9 | QUEUE = Queue.Queue()
10 | SSH_USERNAME = 'ubuntu'
11 | SSH_KEY = '/home/xianglong/.ssh/admin.pem'
12 |
13 | HOSTS = [
14 | ['host-name', 'public-ip', 'private-ip'],
15 | ]
16 | THREAD_NUM = 10
17 | ZABBIX_SERVER = '127.0.0.1'
18 |
19 |
20 | def get_list(filename):
21 | lst = []
22 | with open(filename, 'r') as f:
23 | for i in f.readlines():
24 | lst.append(i.rstrip().split())
25 | return lst
26 |
27 |
28 | class SSH(paramiko.SSHClient):
29 |
30 | def call(self, command, bufsize=-1):
31 | new_exec = self._transport.open_session()
32 | new_exec.exec_command(command)
33 |
34 | stdin = new_exec.makefile('wb', bufsize)
35 | stdout = new_exec.makefile('rb', bufsize)
36 | stderr = new_exec.makefile('rb', bufsize)
37 | status = new_exec.recv_exit_status()
38 |
39 | return stdin, stdout, stderr, status
40 |
41 |
42 | def connect(ip):
43 | """ connect server via ssh protocol """
44 | session = SSH()
45 | session.set_missing_host_key_policy(paramiko.AutoAddPolicy())
46 | rsa_key = paramiko.RSAKey.from_private_key_file(SSH_KEY)
47 |
48 | try:
49 | session.connect(ip, 22, username=SSH_USERNAME, pkey=rsa_key, timeout=15)
50 | except socket.timeout:
51 | print '%s connect timeout' % ip
52 | return None
53 |
54 | return session
55 |
56 |
57 | def general_task(name):
58 | tasks = [
59 | [1, 'sudo mv /etc/zabbix/zabbix_agentd.conf /tmp/'],
60 | [1, 'sudo service zabbix-agent stop'],
61 | [2, 'sudo apt-get purge zabbix_agent -y'],
62 | [2, 'sudo killall zabbix_agentd'],
63 | [3, 'sudo mv /usr/local/zabbix /tmp/zabbix_%s' % time.time()],
64 | [3, 'sudo userdel zabbix'],
65 | [3, 'rm zabbix_agents_2.4.4.linux2_6.amd64.tar.gz'],
66 | [4, 'sudo wget http://www.zabbix.com/downloads/2.4.4/zabbix_agents_2.4.4.linux2_6.amd64.tar.gz'],
67 | [3, 'sudo mkdir /usr/local/zabbix'],
68 | [5, 'sudo tar -zxvf zabbix_agents_2.4.4.linux2_6.amd64.tar.gz -C /usr/local/zabbix'],
69 | [6, 'sudo chown -R root:root /usr/local/zabbix'],
70 | [7, "sudo sed -i -e 's/ServerActive=127.0.0.1/ServerActive=%s/g' /usr/local/zabbix/conf/zabbix_agentd.conf"
71 | % ZABBIX_SERVER],
72 | [8, "sudo sed -i -e 's/Server=127.0.0.1/Server=%s/g' /usr/local/zabbix/conf/zabbix_agentd.conf"
73 | % ZABBIX_SERVER],
74 | [9, "sudo sed -i -e 's/Hostname=Zabbix\ server/Hostname=%s/g' /usr/local/zabbix/conf/zabbix_agentd.conf"
75 | % name],
76 | [3, 'sudo useradd zabbix'],
77 | [12, 'sudo /usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/conf/zabbix_agentd.conf']
78 | ]
79 |
80 | return tasks
81 |
82 |
83 | def task(host):
84 | tasks = general_task(host[0])
85 | session = connect(host[1])
86 | if session:
87 | for command in tasks:
88 | stdin, stdout, stderr, status = session.call(command[1])
89 | if status != 0 and command[0] < 4:
90 | print 'Host: %s, Failed Command: %s' % (host, command[1])
91 | elif status != 0 and command[0] >= 4:
92 | print 'Host: %s, Failed Command: %s' % (host, command[1])
93 | session.close()
94 | else:
95 | print '%s execute %s success' % (host, command[1])
96 | print host[0], host[1], '|'
97 |
98 |
99 | class ThreadTask(threading.Thread):
100 | def __init__(self, queue):
101 | threading.Thread.__init__(self)
102 | self.queue = queue
103 |
104 | def run(self):
105 | while True:
106 | host = self.queue.get()
107 | try:
108 | print 'Task of %s Start.' % host
109 | task(host)
110 | except Exception, e:
111 | print 'Task of %s Failed: %s' % (host, e)
112 | self.queue.task_done()
113 |
114 |
115 | def install():
116 | for i in range(THREAD_NUM):
117 | t = ThreadTask(QUEUE)
118 | t.setDaemon(True)
119 | t.start()
120 |
121 | for host in HOSTS:
122 | QUEUE.put(host)
123 | QUEUE.join()
124 |
125 | if __name__ == '__main__':
126 | install()
127 |
--------------------------------------------------------------------------------
/scripts/send_mail.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # -*- coding: utf-8 -*-
3 | import sys
4 | import smtplib
5 | import requests
6 | from email.mime.text import MIMEText
7 |
8 | MAIL_HOST = "smtp.163.com"
9 | MAIL_USER = "wuxianglong098@163.com"
10 | MAIL_PWD = "password"
11 |
12 |
13 | def send_mail(to_list, subject, body):
14 | msg = MIMEText(body)
15 | msg['Subject'] = subject
16 | msg['From'] = MAIL_USER
17 | msg['To'] = to_list
18 | try:
19 | s = smtplib.SMTP()
20 | s.connect(MAIL_HOST)
21 | s.login(MAIL_USER, MAIL_PWD)
22 | s.sendmail(MAIL_USER, to_list, msg.as_string())
23 | s.close()
24 | return True
25 | except Exception, e:
26 | print str(e)
27 | return False
28 |
29 |
30 | def send_email_by_mailgun(mail_to, subject, body):
31 | r = requests.post('https://api.mailgun.net/v2/colorba.us/messages', auth=('api', ''),
32 | data={'from': '', 'to': ['%s' % mail_to], 'subject': '%s' % subject, 'text': '%s' % body})
33 | print r.text
34 |
35 |
36 | if __name__ == '__main__':
37 | send_mail(*sys.argv[1: 4])
38 |
39 |
--------------------------------------------------------------------------------
/scripts/zabbix-nginx.conf:
--------------------------------------------------------------------------------
1 | server {
2 | server_name 127.0.0.1;
3 | root /usr/share/zabbix/;
4 | index index.php index.html;
5 | client_max_body_size 5m;
6 | client_body_buffer_size 128k;
7 |
8 | access_log /var/log/nginx/zabbix-access.log;
9 |
10 | location ~ \.php$ {
11 | fastcgi_pass unix:/var/run/zabbix.socket;
12 | include fastcgi_params;
13 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
14 | fastcgi_param SCRIPT_NAME $fastcgi_script_name;
15 | }
16 |
17 | location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
18 | expires max;
19 | log_not_found off;
20 | }
21 |
22 | location ~ /\.ht {
23 | deny all;
24 | }
25 |
26 | location ~ /\. {
27 | deny all;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/scripts/zabbix_conf.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # -*- coding: utf-8 -*-
3 | import json
4 | import time
5 | import requests
6 |
7 | HOSTS = [
8 | ['host-name', 'public-ip', 'private-ip'],
9 | ]
10 |
11 | DOMAIN = "http://127.0.0.1/api_jsonrpc.php"
12 | JSON_HEADERS = {"content-type": "application/json"}
13 | GROUP_ID = 2
14 | TEMPLATE_ID = 10001
15 |
16 |
17 | def get_list(filename):
18 | lst = []
19 | with open(filename, 'r') as f:
20 | for i in f.readlines():
21 | lst.append(i.rstrip())
22 | return lst
23 |
24 |
25 | def get_token():
26 | login_data = json.dumps({
27 | "jsonrpc": "2.0",
28 | "method": "user.login",
29 | "params": {
30 | "user": "Admin",
31 | "password": "password",
32 | },
33 | "id": 1
34 | })
35 | request = requests.post(DOMAIN, data=login_data, headers=JSON_HEADERS, timeout=30)
36 |
37 | print request.text
38 |
39 | return request.json()['result']
40 |
41 |
42 | def add_host(host):
43 | data = json.dumps({
44 | "jsonrpc": "2.0",
45 | "method": "host.create",
46 | "params": {
47 | "host": "%s" % host[0],
48 | "interfaces": [
49 | {
50 | "type": 1,
51 | "main": 1,
52 | "useip": 1,
53 | "ip": host[2],
54 | "dns": "",
55 | "port": "10050"
56 | }
57 | ],
58 | "groups": [{
59 | "groupid": GROUP_ID,
60 | }],
61 | "templates": [{
62 | "templateid": TEMPLATE_ID,
63 | }],
64 | },
65 | "auth": get_token(),
66 | "id": 1,
67 | })
68 | request = requests.post(DOMAIN, data=data, headers=JSON_HEADERS)
69 | print data
70 | print request.json()
71 |
72 |
73 | if __name__ == "__main__":
74 | for ht in HOSTS:
75 | print ht
76 | add_host(ht)
77 |
--------------------------------------------------------------------------------
/tcp-port/README.md:
--------------------------------------------------------------------------------
1 | Template for Discovery Port
2 | ===========================
3 |
4 | Check TCP port status in Zabbix using discovery.
5 |
6 | INSTALL
7 | -------
8 |
9 | ### Add User Parameters
10 |
11 | Copy get_port.py to /usr/local/zabbix/bin/ and run "sudo chmod 777 get_port.py"
12 | Copy tcp-port.conf to /usr/local/zabbix/conf/zabbix_agentd/. Restart Zabbix agent.
13 | Add line "Include=/usr/local/zabbix/conf/zabbix_agentd/*.conf" in /usr/local/zabbix/conf/zabbix_agentd.conf
14 |
15 | ### Add discovery
16 |
17 | See: http://www.linuxyan.com/cacti-nagios/396.html
18 |
19 |
--------------------------------------------------------------------------------
/tcp-port/get_port.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | #-*- coding: utf-8 -*-
3 | import os
4 | import json
5 |
6 | ports = [line.split()[3].split(':')[1] for line in os.popen('netstat -tpln | grep LISTEN | grep -v tcp6').readlines()]
7 | data = {
8 | 'data': [{'{#TCP_PORT}': p} for p in set(ports)],
9 | }
10 | print json.dumps(data, sort_keys=True, indent=4)
11 |
12 |
--------------------------------------------------------------------------------
/tcp-port/tcp-port.conf:
--------------------------------------------------------------------------------
1 | UserParameter=tcpportlisten,sudo /usr/local/zabbix/bin/get_port.py
2 |
--------------------------------------------------------------------------------