Skip to content

Commit

Permalink
Zabbix monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
big-town committed Sep 4, 2017
1 parent 5d5a33e commit 46c8ca9
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 0 deletions.
5 changes: 5 additions & 0 deletions zabbix/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
all: main.c getdata.c
gcc -v -O2 main.c getdata.c -o zabbix_data
install: zabbix_data
cp zabbix_data /usr/local/bin

10 changes: 10 additions & 0 deletions zabbix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Это минимальный пакет для мониторинга extFilter через файл /var/run/extFilter_stat в zabbix.
Установка:
make && make install
Необходимо также установить zabbix-agent.

Затем добавить в файл /etc/zabbix/zabbix_agent.conf строку
UserParameter=extfilter.stat[*],zabbix_data $1
и перезапустить сервис агента.

Затем импорти ровать шаблон через WEB-интерфейс.
32 changes: 32 additions & 0 deletions zabbix/getdata.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <string.h>
#include <ctype.h>
char* trimall(char* s){
char *temp=malloc(255);
memset(temp,0,sizeof(temp));
int i=0,j=0;
char c;
while( (c=*(s+i))!= 0){
if(!isspace(c)){
*(temp+j)=c;
j++;
}
i++;
}
return temp;
}
char* getparam(char *s){
char *temp=malloc(255),*c;
memset(temp,0,sizeof(temp));
if((c=strchr(s,'='))!=NULL){
strncpy(temp,s,c-s);
}
return temp;
}
char* getvalue(char *s){
char *temp=malloc(255),*c;
memset(temp,0,sizeof(temp));
if((c=strchr(s,'='))!=NULL){
strcpy(temp,(c+1));
}
return temp;
}
2 changes: 2 additions & 0 deletions zabbix/getdata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
char* trimall(char* s);
char* getparam(char* s);
46 changes: 46 additions & 0 deletions zabbix/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "getdata.h"
#include <stdio.h>
#define statfile "/var/run/extFilter_stat"
void main(char argc, char **argv){
if(argc!=2){
fprintf(stderr, "Usage example:\n \tzabbix_data extfilter.discovery\n\t or \n\tzabbix_data allports.received_packets\n",statfile);
exit(1);
}
if((argc==2) && !strcmp(argv[1],"extfilter.discovery")){
char temp[255];
memset(temp,0,sizeof(temp));
FILE *sf=fopen(statfile,"r");
if(sf==NULL){
fprintf(stderr, "File %s not found!\n",statfile);
exit(1);
}
puts("{\n\"data\":[");
int commafirst=1;
while(fgets(temp,255,sf)!=NULL){
if(commafirst){
printf("{\"{#STATPARAM}\":\"%s\"}",getparam(trimall(temp)));
}else{
printf(",\n{\"{#STATPARAM}\":\"%s\"}",getparam(trimall(temp)));
}
commafirst=0;
}
puts("\n]\n}");
fclose(sf);
}
if(argc==2 &&
(strstr(argv[1],"worker.")!=NULL) || (strstr(argv[1],"allworkers.")!=NULL) || (strstr(argv[1],"allports.")!=NULL) ){
char temp[255];
memset(temp,0,sizeof(temp));
FILE *sf=fopen(statfile,"r");
if(sf==NULL){
fprintf(stderr, "File %s not found!\n",statfile);
exit(1);
}
while(fgets(temp,255,sf)!=NULL){
if( !strcmp(getparam(trimall(temp)),trimall(argv[1])) ){
puts(getvalue(trimall(temp)));
}
}
fclose(sf);
}
}
101 changes: 101 additions & 0 deletions zabbix/zbx_extfilter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>2.0</version>
<date>2017-09-04T00:56:44Z</date>
<groups>
<group>
<name>extfilter</name>
</group>
</groups>
<templates>
<template>
<template>extfilter</template>
<name>extfilter</name>
<groups>
<group>
<name>extfilter</name>
</group>
</groups>
<applications/>
<items/>
<discovery_rules>
<discovery_rule>
<name>extfilter</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>extfilter.stat[&quot;extfilter.discovery&quot;]</key>
<delay>300</delay>
<status>0</status>
<allowed_hosts/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<delay_flex/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<filter>{#STATPARAM}:</filter>
<lifetime>30</lifetime>
<description/>
<item_prototypes>
<item_prototype>
<name>extfilter.stat.$1</name>
<type>0</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>extfilter.stat[{#STATPARAM}]</key>
<delay>300</delay>
<history>90</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications/>
<valuemap/>
<logtimefmt/>
</item_prototype>
</item_prototypes>
<trigger_prototypes/>
<graph_prototypes/>
<host_prototypes/>
</discovery_rule>
</discovery_rules>
<macros/>
<templates/>
<screens/>
</template>
</templates>
</zabbix_export>

0 comments on commit 46c8ca9

Please sign in to comment.