diff -x .cvsignore -Nr --unified=5 nagios-2.0rc2.org/base/config.c nagios-2.0rc2.snmppatch/base/config.c --- nagios-2.0rc2.org/base/config.c 2005-12-27 00:18:14.000000000 +0100 +++ nagios-2.0rc2.snmppatch/base/config.c 2006-01-13 12:16:10.331028384 +0100 @@ -1843,10 +1843,17 @@ warnings++; } found=FALSE; + if (temp_host->community==NULL) { + snprintf(temp_buffer,sizeof(temp_buffer),"Warning: Host '%s' has no community defined!",temp_host->name); + temp_buffer[sizeof(temp_buffer)-1]='\x0'; + write_to_logs_and_console(temp_buffer,NSLOG_VERIFICATION_WARNING,TRUE); + warnings++; + } + #ifdef REMOVED_061303 /* make sure each host is a member of at least one hostgroup */ for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){ temp_hostgroupmember=find_hostgroupmember(temp_host->name,temp_hostgroup); if(temp_hostgroupmember!=NULL){ diff -x .cvsignore -Nr --unified=5 nagios-2.0rc2.org/base/utils.c nagios-2.0rc2.snmppatch/base/utils.c --- nagios-2.0rc2.org/base/utils.c 2006-01-04 17:39:57.000000000 +0100 +++ nagios-2.0rc2.snmppatch/base/utils.c 2006-01-13 17:51:20.111877008 +0100 @@ -929,10 +929,18 @@ free(macro_x[MACRO_HOSTGROUPALIAS]); macro_x[MACRO_HOSTGROUPALIAS]=NULL; if(temp_hostgroup!=NULL) macro_x[MACRO_HOSTGROUPALIAS]=strdup(temp_hostgroup->alias); + /* patch define SNMP Community */ + if(macro_x[MACRO_SNMPCOMMUNITY]!=NULL) + free(macro_x[MACRO_SNMPCOMMUNITY]); + macro_x[MACRO_SNMPCOMMUNITY]=NULL; + if (strdup(hst->community)!=NULL) + macro_x[MACRO_SNMPCOMMUNITY]=strdup(hst->community); + /* end */ + if((temp_hostextinfo=find_hostextinfo(hst->name))){ /* get the action url */ if(macro_x[MACRO_HOSTACTIONURL]!=NULL) free(macro_x[MACRO_HOSTACTIONURL]); @@ -1264,11 +1272,14 @@ else{ macro_ondemand=strdup(hst->plugin_output); strip(macro_ondemand); } } - + /* patch define SNMP Community */ + else if(!strcmp(macro,"SNMPCOMMUNITY")) + macro_ondemand=strdup(hst->community); + /* END */ /* get the performance data */ else if(!strcmp(macro,"HOSTPERFDATA")){ if(hst->perf_data==NULL) macro_ondemand=NULL; else{ @@ -2387,10 +2398,13 @@ add_macrox_name(MACRO_TOTALSERVICEPROBLEMS,"TOTALSERVICEPROBLEMS"); add_macrox_name(MACRO_TOTALSERVICEPROBLEMSUNHANDLED,"TOTALSERVICEPROBLEMSUNHANDLED"); add_macrox_name(MACRO_PROCESSSTARTTIME,"PROCESSSTARTTIME"); add_macrox_name(MACRO_HOSTCHECKTYPE,"HOSTCHECKTYPE"); add_macrox_name(MACRO_SERVICECHECKTYPE,"SERVICECHECKTYPE"); + /* patch define SNMP Community */ + add_macrox_name(MACRO_SNMPCOMMUNITY,"SNMPCOMMUNITY"); + /* END */ #ifdef DEBUG0 printf("init_macrox_names() end\n"); #endif diff -x .cvsignore -Nr --unified=5 nagios-2.0rc2.org/cgi/config.c nagios-2.0rc2.snmppatch/cgi/config.c --- nagios-2.0rc2.org/cgi/config.c 2005-11-16 09:49:35.000000000 +0100 +++ nagios-2.0rc2.snmppatch/cgi/config.c 2006-01-13 12:16:10.342026712 +0100 @@ -449,10 +449,13 @@ printf("Address"); printf("Parent Hosts"); printf("Max. Check Attempts"); printf("Check Interval\n"); printf("Host Check Command"); + /* patch define SNMP Community */ + printf("SNMP Community"); + /* END */ printf("Obsess Over\n"); printf("Enable Active Checks\n"); printf("Enable Passive Checks\n"); printf("Check Freshness\n"); printf("Freshness Threshold\n"); @@ -512,10 +515,14 @@ printf(" "); else printf("%s\n",CONFIG_CGI,url_encode(temp_host->host_check_command),temp_host->host_check_command); printf("\n"); + /* patch define SNMP Community */ + printf("%s \n",bg_class,temp_host->community); + /* END */ + printf("%s\n",bg_class,(temp_host->obsess_over_host==TRUE)?"Yes":"No"); printf("%s\n",bg_class,(temp_host->checks_enabled==TRUE)?"Yes":"No"); printf("%s\n",bg_class,(temp_host->accept_passive_host_checks==TRUE)?"Yes":"No"); diff -x .cvsignore -Nr --unified=5 nagios-2.0rc2.org/common/objects.c nagios-2.0rc2.snmppatch/common/objects.c --- nagios-2.0rc2.org/common/objects.c 2005-12-27 19:55:10.000000000 +0100 +++ nagios-2.0rc2.snmppatch/common/objects.c 2006-01-13 12:16:10.352025192 +0100 @@ -924,13 +924,15 @@ return new_timerange; } /* add a new host definition */ -host *add_host(char *name, char *alias, char *address, char *check_period, int check_interval, int max_attempts, int notify_up, int notify_down, int notify_unreachable, int notify_flapping, int notification_interval, char *notification_period, int notifications_enabled, char *check_command, int checks_enabled, int accept_passive_checks, char *event_handler, int event_handler_enabled, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int stalk_up, int stalk_down, int stalk_unreachable, int process_perfdata, int failure_prediction_enabled, char *failure_prediction_options, int check_freshness, int freshness_threshold, int retain_status_information, int retain_nonstatus_information, int obsess_over_host){ +/* patch define SNMP Community */ +host *add_host(char *name, char *alias, char *address, char *check_period, int check_interval, int max_attempts, int notify_up, int notify_down, int notify_unreachable, int notify_flapping, int notification_interval, char *notification_period, int notifications_enabled, char *check_command, int checks_enabled, int accept_passive_checks, char *event_handler, int event_handler_enabled, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int stalk_up, int stalk_down, int stalk_unreachable, int process_perfdata, int failure_prediction_enabled, char *failure_prediction_options, int check_freshness, int freshness_threshold, int retain_status_information, int retain_nonstatus_information, int obsess_over_host,char *community){ host *temp_host; host *new_host; +/* END */ #ifdef NSCORE char temp_buffer[MAX_INPUT_BUFFER]; int x; #endif @@ -952,10 +954,13 @@ strip(alias); strip(address); strip(check_command); strip(event_handler); strip(notification_period); + /* patch define SNMP Community */ + strip(community); + /* END */ if(!strcmp(name,"") || !strcmp(alias,"") || !strcmp(address,"")){ #ifdef NSCORE snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Host name, alias, or address is NULL\n"); temp_buffer[sizeof(temp_buffer)-1]='\x0'; @@ -1309,10 +1314,39 @@ } } else new_host->failure_prediction_options=NULL; + /* patch define SNMP Community */ + if (community==NULL) { + new_host->community=NULL; + } else { + new_host->community=strdup(community); + if(new_host->community==NULL){ +#ifdef NSCORE + snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for host '%s' community\n",name); + temp_buffer[sizeof(temp_buffer)-1]='\x0'; + write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE); +#endif + if(new_host->event_handler!=NULL) + free(new_host->event_handler); + if(new_host->host_check_command!=NULL) + free(new_host->host_check_command); + if(new_host->notification_period!=NULL) + free(new_host->notification_period); + if (new_host->failure_prediction_options!=NULL) + free(new_host->failure_prediction_options); + free(new_host->check_period); + free(new_host->address); + free(new_host->alias); + free(new_host->name); + free(new_host); + return NULL; + } + } + /* END */ + new_host->parent_hosts=NULL; new_host->max_attempts=max_attempts; new_host->contact_groups=NULL; new_host->check_interval=check_interval; @@ -1482,10 +1516,13 @@ #ifdef DEBUG1 printf("\tHost Name: %s\n",new_host->name); printf("\tHost Alias: %s\n",new_host->alias); printf("\tHost Address: %s\n",new_host->address); + /* patch define SNMP Community */ + printf("\tSNMP Community: %s\n",new_host->community); + /* END */ printf("\tHost Check Command: %s\n",new_host->host_check_command); printf("\tMax. Check Attempts: %d\n",new_host->max_attempts); printf("\tHost Event Handler: %s\n",(new_host->event_handler==NULL)?"N/A":new_host->event_handler); printf("\tNotify On Down: %s\n",(new_host->notify_on_down==1)?"yes":"no"); printf("\tNotify On Unreachable: %s\n",(new_host->notify_on_unreachable==1)?"yes":"no"); diff -x .cvsignore -Nr --unified=5 nagios-2.0rc2.org/include/nagios.h.in nagios-2.0rc2.snmppatch/include/nagios.h.in --- nagios-2.0rc2.org/include/nagios.h.in 2006-01-04 17:39:57.000000000 +0100 +++ nagios-2.0rc2.snmppatch/include/nagios.h.in 2006-01-13 12:17:14.473277280 +0100 @@ -47,11 +47,11 @@ #define MAX_STATEID_LENGTH 2 #define MAX_PERCENTCHANGE_LENGTH 8 #define MACRO_ENV_VAR_PREFIX "NAGIOS_" -#define MACRO_X_COUNT 99 /* size of macro_x[] array */ +#define MACRO_X_COUNT 100 /* size of macro_x[] array */ #define MACRO_HOSTNAME 0 #define MACRO_HOSTALIAS 1 #define MACRO_HOSTADDRESS 2 #define MACRO_SERVICEDESC 3 @@ -148,10 +148,14 @@ #define MACRO_TOTALSERVICEPROBLEMS 94 #define MACRO_TOTALSERVICEPROBLEMSUNHANDLED 95 #define MACRO_PROCESSSTARTTIME 96 #define MACRO_HOSTCHECKTYPE 97 #define MACRO_SERVICECHECKTYPE 98 +/* patch define SNMP Community */ +#define MACRO_SNMPCOMMUNITY 99 +/* END */ + #define DEFAULT_LOG_LEVEL 1 /* log all events to main log file */ #define DEFAULT_USE_SYSLOG 1 /* log events to syslog? 1=yes, 0=no */ diff -x .cvsignore -Nr --unified=5 nagios-2.0rc2.org/include/objects.h nagios-2.0rc2.snmppatch/include/objects.h --- nagios-2.0rc2.org/include/objects.h 2005-12-27 19:55:10.000000000 +0100 +++ nagios-2.0rc2.snmppatch/include/objects.h 2006-01-13 12:16:10.356024584 +0100 @@ -157,10 +157,13 @@ int retain_status_information; int retain_nonstatus_information; int failure_prediction_enabled; char *failure_prediction_options; int obsess_over_host; + /* patch define SNMP Community */ + char *community; + /* END */ #ifdef NSCORE int problem_has_been_acknowledged; int acknowledgement_type; int check_type; int current_state; @@ -530,11 +533,13 @@ /**** Object Creation Functions ****/ contact *add_contact(char *,char *,char *,char *,char **,char *,char *,int,int,int,int,int,int,int,int,int); /* adds a contact definition */ commandsmember *add_service_notification_command_to_contact(contact *,char *); /* adds a service notification command to a contact definition */ commandsmember *add_host_notification_command_to_contact(contact *,char *); /* adds a host notification command to a contact definition */ -host *add_host(char *,char *,char *,char *,int,int,int,int,int,int,int,char *,int,char *,int,int,char *,int,int,double,double,int,int,int,int,int,char *,int,int,int,int,int); /* adds a host definition */ +/* patch define SNMP Community */ +host *add_host(char *,char *,char *,char *,int,int,int,int,int,int,int,char *,int,char *,int,int,char *,int,int,double,double,int,int,int,int,int,char *,int,int,int,int,int,char *); /* adds a host definition */ +/* END */ hostsmember *add_parent_host_to_host(host *,char *); /* adds a parent host to a host definition */ contactgroupsmember *add_contactgroup_to_host(host *,char *); /* adds a contactgroup to a host definition */ timeperiod *add_timeperiod(char *,char *); /* adds a timeperiod definition */ timerange *add_timerange_to_timeperiod(timeperiod *,int,unsigned long,unsigned long); /* adds a timerange to a timeperiod definition */ hostgroup *add_hostgroup(char *,char *); /* adds a hostgroup definition */ diff -x .cvsignore -Nr --unified=5 nagios-2.0rc2.org/xdata/xodtemplate.c nagios-2.0rc2.snmppatch/xdata/xodtemplate.c --- nagios-2.0rc2.org/xdata/xodtemplate.c 2006-01-07 20:59:25.000000000 +0100 +++ nagios-2.0rc2.snmppatch/xdata/xodtemplate.c 2006-01-13 12:16:10.375021696 +0100 @@ -1261,10 +1261,13 @@ new_host->have_retain_nonstatus_information=FALSE; new_host->has_been_resolved=FALSE; new_host->register_object=TRUE; new_host->_config_file=config_file; new_host->_start_line=start_line; + /* patch define SNMP Community */ + new_host->community=NULL; + /* END */ /* add new host to head of list in memory */ new_host->next=xodtemplate_host_list; xodtemplate_host_list=new_host; @@ -2843,11 +2846,21 @@ temp_host->retain_nonstatus_information=(atoi(value)>0)?TRUE:FALSE; temp_host->have_retain_nonstatus_information=TRUE; } else if(!strcmp(variable,"register")) temp_host->register_object=(atoi(value)>0)?TRUE:FALSE; - else{ + /* patch define SNMP Community */ + else if(!strcmp(variable,"community")){ + temp_host->community=strdup(value); + if(temp_host->community==NULL){ +#ifdef DEBUG1 + printf("Error: Could not allocate memory for community name.\n"); +#endif + return ERROR; + } + } else{ + /* END */ #ifdef NSCORE snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Invalid host object directive '%s'.\n",variable); temp_buffer[sizeof(temp_buffer)-1]='\x0'; write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE); #endif @@ -6054,10 +6067,14 @@ } if(this_host->have_retain_nonstatus_information==FALSE && template_host->have_retain_nonstatus_information==TRUE){ this_host->retain_nonstatus_information=template_host->retain_nonstatus_information; this_host->have_retain_nonstatus_information=TRUE; } + /* patch define SNMP Community */ + if(this_host->community==NULL && template_host->community!=NULL) + this_host->community=strdup(template_host->community); + /* END */ #ifdef DEBUG0 printf("xodtemplate_resolve_host() end\n"); #endif @@ -8027,11 +8044,13 @@ this_host->alias=strdup(this_host->host_name); if(this_host->address==NULL && this_host->host_name!=NULL) this_host->address=strdup(this_host->host_name); /* add the host definition */ - new_host=add_host(this_host->host_name,this_host->alias,(this_host->address==NULL)?this_host->host_name:this_host->address,this_host->check_period,this_host->check_interval,this_host->max_check_attempts,this_host->notify_on_recovery,this_host->notify_on_down,this_host->notify_on_unreachable,this_host->notify_on_flapping,this_host->notification_interval,this_host->notification_period,this_host->notifications_enabled,this_host->check_command,this_host->active_checks_enabled,this_host->passive_checks_enabled,this_host->event_handler,this_host->event_handler_enabled,this_host->flap_detection_enabled,this_host->low_flap_threshold,this_host->high_flap_threshold,this_host->stalk_on_up,this_host->stalk_on_down,this_host->stalk_on_unreachable,this_host->process_perf_data,this_host->failure_prediction_enabled,this_host->failure_prediction_options,this_host->check_freshness,this_host->freshness_threshold,this_host->retain_status_information,this_host->retain_nonstatus_information,this_host->obsess_over_host); + /* patch define SNMP Community */ + new_host=add_host(this_host->host_name,this_host->alias,(this_host->address==NULL)?this_host->host_name:this_host->address,this_host->check_period,this_host->check_interval,this_host->max_check_attempts,this_host->notify_on_recovery,this_host->notify_on_down,this_host->notify_on_unreachable,this_host->notify_on_flapping,this_host->notification_interval,this_host->notification_period,this_host->notifications_enabled,this_host->check_command,this_host->active_checks_enabled,this_host->passive_checks_enabled,this_host->event_handler,this_host->event_handler_enabled,this_host->flap_detection_enabled,this_host->low_flap_threshold,this_host->high_flap_threshold,this_host->stalk_on_up,this_host->stalk_on_down,this_host->stalk_on_unreachable,this_host->process_perf_data,this_host->failure_prediction_enabled,this_host->failure_prediction_options,this_host->check_freshness,this_host->freshness_threshold,this_host->retain_status_information,this_host->retain_nonstatus_information,this_host->obsess_over_host,this_host->community); + /* END */ #ifdef TEST_DEBUG printf("HOST: %s, MAXATTEMPTS: %d, NOTINVERVAL: %d \n",this_host->host_name,this_host->max_check_attempts,this_host->notification_interval); #endif @@ -9454,10 +9473,14 @@ fprintf(fp,"\tcheck_interval\t%d\n",temp_host->check_interval); fprintf(fp,"\tmax_check_attempts\t%d\n",temp_host->max_check_attempts); fprintf(fp,"\tactive_checks_enabled\t%d\n",temp_host->active_checks_enabled); fprintf(fp,"\tpassive_checks_enabled\t%d\n",temp_host->passive_checks_enabled); fprintf(fp,"\tobsess_over_host\t%d\n",temp_host->obsess_over_host); + /* patch define SNMP Community */ + if (temp_host->community) + fprintf(fp,"\tcommunity\t%s\n",temp_host->community); + /* END */ fprintf(fp,"\tevent_handler_enabled\t%d\n",temp_host->event_handler_enabled); fprintf(fp,"\tlow_flap_threshold\t%f\n",temp_host->low_flap_threshold); fprintf(fp,"\thigh_flap_threshold\t%f\n",temp_host->high_flap_threshold); fprintf(fp,"\tflap_detection_enabled\t%d\n",temp_host->flap_detection_enabled); fprintf(fp,"\tfreshness_threshold\t%d\n",temp_host->freshness_threshold); @@ -9954,10 +9977,13 @@ free(this_host->check_period); free(this_host->event_handler); free(this_host->contact_groups); free(this_host->notification_period); free(this_host->failure_prediction_options); + /* patch define SNMP Community */ + free(this_host->community); + /* END */ free(this_host); } xodtemplate_host_list=NULL; /* free memory allocated to service list (chained hash) */ diff -x .cvsignore -Nr --unified=5 nagios-2.0rc2.org/xdata/xodtemplate.h nagios-2.0rc2.snmppatch/xdata/xodtemplate.h --- nagios-2.0rc2.org/xdata/xodtemplate.h 2005-11-16 09:49:35.000000000 +0100 +++ nagios-2.0rc2.snmppatch/xdata/xodtemplate.h 2006-01-13 12:16:10.377021392 +0100 @@ -158,10 +158,11 @@ int check_interval; int max_check_attempts; int active_checks_enabled; int passive_checks_enabled; int obsess_over_host; + char *community; char *event_handler; int event_handler_enabled; int check_freshness; int freshness_threshold; float low_flap_threshold;