Changeset 4299e397f43c438472a1933713f8d35e706c97cb

Show
Ignore:
Timestamp:
09/21/11 19:00:42 (3 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1316631642 -0400
git-parent:

[d0f189b538d40f75068aac027df6e9f9245a4d5a], [022178b72fc213634c638c89545331c05680d374]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1316631642 -0400
Message:

Merge branch 'dns_resolve_rtype'

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules/check_test.c

    rf0c65b7 rde645be  
    9797noit_fire_check(xmlNodePtr attr, xmlNodePtr config, const char **error) { 
    9898  char *target = NULL, *name = NULL, *module = NULL, *filterset = NULL; 
    99   int timeout = 0; 
     99  char *resolve_rtype = NULL; 
     100  int timeout = 0, flags = NP_TRANSIENT; 
    100101  noit_module_t *m; 
    101102  noit_check_t *c = NULL; 
     
    116117      timeout = atoi(timeout_str); 
    117118      free(timeout_str); 
    118     } 
     119    } else if(!strcmp((char *)a->name, "resolve_rtype"))  
     120      resolve_rtype = (char *)xmlNodeGetContent(a); 
    119121  } 
    120122  m = noit_module_lookup(module); 
     
    139141    goto error; 
    140142  } 
     143  flags |= noit_calc_rtype_flag(resolve_rtype); 
    141144  c = calloc(1, sizeof(*c)); 
    142145  noit_check_update(c, target, name, filterset, 
    143                     conf_hash, 0, timeout, NULL, NP_TRANSIENT); 
     146                    conf_hash, 0, timeout, NULL, flags); 
    144147  c->module = strdup(module); 
    145148  uuid_generate(c->checkid); 
     
    157160  if(module) xmlFree(module); 
    158161  if(filterset) xmlFree(filterset); 
     162  if (resolve_rtype) xmlFree(resolve_rtype); 
    159163  return c; 
    160164} 
  • src/noit.conf.in

    rbb10f44 r68aa702  
    109109    </acl> 
    110110  </rest> 
    111   <checks max_initial_stutter="30000" filterset="default" transient_min_period="1000" transient_period_granularity="500"> 
     111  <checks max_initial_stutter="30000" filterset="default" 
     112          resolve_rtype="prefer-ipv4" 
     113          transient_min_period="1000" transient_period_granularity="500"> 
    112114    <check uuid="f7cea020-f19d-11dd-85a6-cb6d3a2207dc" module="selfcheck" target="10.80.117.90" period="5000" timeout="4000"/> 
    113115    <check uuid="1b4e28ba-2fa1-11d2-883f-b9b761bde3fb" module="ping_icmp" target="10.80.116.4" period="15000" timeout="14000"/> 
  • src/noit_check.c

    rf207009 r16b1bdd  
    107107} 
    108108int 
     109noit_calc_rtype_flag(char *resolve_rtype) { 
     110  int flags = 0; 
     111  flags |= strcmp(resolve_rtype, PREFER_IPV6) == 0 || 
     112           strcmp(resolve_rtype, FORCE_IPV6) == 0 ? NP_PREFER_IPV6 : 0; 
     113  flags |= strcmp(resolve_rtype, FORCE_IPV4) == 0 || 
     114           strcmp(resolve_rtype, FORCE_IPV6) == 0 ? NP_SINGLE_RESOLVE : 0; 
     115  return flags; 
     116} 
     117int 
    109118noit_check_max_initial_stutter() { 
    110119  int stutter; 
     
    150159    char filterset[256] = ""; 
    151160    char oncheck[1024] = ""; 
     161    char resolve_rtype[16] = ""; 
    152162    int no_period = 0; 
    153163    int no_oncheck = 0; 
     
    183193    if(!INHERIT(stringbuf, filterset, filterset, sizeof(filterset))) 
    184194      filterset[0] = '\0'; 
     195     
     196    if (!INHERIT(stringbuf, resolve_rtype, resolve_rtype, sizeof(resolve_rtype))) 
     197      strlcpy(resolve_rtype, PREFER_IPV4, sizeof(resolve_rtype)); 
    185198 
    186199    if(!MYATTR(stringbuf, name, name, sizeof(name))) 
     
    217230    if(busted) flags |= (NP_UNCONFIG|NP_DISABLED); 
    218231    else if(disabled) flags |= NP_DISABLED; 
     232 
     233    flags |= noit_calc_rtype_flag(resolve_rtype); 
    219234 
    220235    if(noit_hash_retrieve(&polls, (char *)uuid, UUID_SIZE, 
     
    569584  } a; 
    570585 
    571  
    572   family = AF_INET; 
     586  family = NOIT_CHECK_PREFER_V6(new_check) ? AF_INET6 : AF_INET; 
    573587  rv = inet_pton(family, ip_str, &a); 
    574   if(rv != 1) { 
    575     family = AF_INET6
     588  if(rv != 1 && !NOIT_CHECK_SINGLE_RESOLVE(new_check)) { 
     589    family = family == AF_INET ? AF_INET6 : AF_INET
    576590    rv = inet_pton(family, ip_str, &a); 
    577591    if(rv != 1) { 
     
    624638  if(new_check->target) free(new_check->target); 
    625639  new_check->target = strdup(target); 
     640 
     641  // apply resolution flags to check. 
     642  if (flags & NP_PREFER_IPV6) 
     643    new_check->flags |= NP_PREFER_IPV6; 
     644  else 
     645    new_check->flags &= ~NP_PREFER_IPV6; 
     646  if (flags & NP_SINGLE_RESOLVE) 
     647    new_check->flags |= NP_SINGLE_RESOLVE; 
     648  else 
     649    new_check->flags &= ~NP_SINGLE_RESOLVE; 
    626650 
    627651  if(noit_check_set_ip(new_check, target)) { 
  • src/noit_check.h

    r3081176 r16b1bdd  
    7373#define NP_SUPPRESS_METRICS 0x00002000 
    7474 
     75#define NP_PREFER_IPV6   0x00004000 
     76#define NP_SINGLE_RESOLVE 0x00008000 
     77 
     78#define PREFER_IPV4 "prefer-ipv4" 
     79#define PREFER_IPV6 "prefer-ipv6" 
     80#define FORCE_IPV4  "force-ipv4" 
     81#define FORCE_IPV6  "force-ipv6" 
     82 
    7583#define NP_UNKNOWN '0'             /* stats_t.{available,state} */ 
    7684#define NP_AVAILABLE 'A'           /* stats_t.available */ 
     
    156164/* It is resolved if it is resolved or never needed to be resolved */ 
    157165#define NOIT_CHECK_RESOLVED(a) (((a)->flags & NP_RESOLVED) || (((a)->flags & NP_RESOLVE) == 0)) 
     166#define NOIT_CHECK_PREFER_V6(a) ((a)->flags & NP_PREFER_IPV6) 
     167#define NOIT_CHECK_SINGLE_RESOLVE(a) ((a)->flags & NP_SINGLE_RESOLVE) 
    158168 
    159169API_EXPORT(void) noit_poller_init(); 
     
    245255API_EXPORT(const char *) 
    246256  noit_check_state_string(int16_t state); 
     257API_EXPORT(int) 
     258  noit_calc_rtype_flag(char *resolve_rtype); 
    247259API_EXPORT(int) 
    248260  noit_stats_snprint_metric_value(char *b, int l, metric_t *m); 
  • src/noit_check_rest.c

    r09ecd28 r6033f87  
    197197  SHOW_ATTR(attr,node,module); 
    198198  SHOW_ATTR(attr,node,target); 
     199  SHOW_ATTR(attr,node,resolve_rtype); 
    199200  SHOW_ATTR(attr,node,period); 
    200201  SHOW_ATTR(attr,node,timeout); 
     
    283284          } 
    284285          target = 1; 
     286        } 
     287        else CHECK_N_SET(resolve_rtype) { 
     288          xmlChar *tmp; 
     289          noit_boolean invalid; 
     290          tmp = xmlNodeGetContent(an); 
     291          invalid = strcmp((char *)tmp, PREFER_IPV4) && 
     292                    strcmp((char *)tmp, PREFER_IPV6) && 
     293                    strcmp((char *)tmp, FORCE_IPV4) && 
     294                    strcmp((char *)tmp, FORCE_IPV6); 
     295          xmlFree(tmp); 
     296          if(invalid) { 
     297            *error = "invalid reslove_rtype"; 
     298            return 0; 
     299          } 
    285300        } 
    286301        else CHECK_N_SET(period) { 
     
    356371    ATTR2PROP(name); 
    357372    ATTR2PROP(target); 
     373    ATTR2PROP(resolve_rtype); 
    358374    ATTR2PROP(module); 
    359375    ATTR2PROP(period); 
  • src/noit_conf_checks.c

    r30b3841 r022178b  
    6666  { "/checks", "oncheck", "@oncheck", 0 }, 
    6767  { "/checks", "disable", "@disable", 0 }, 
     68  { "/checks", "resolve_rtype", "@resolve_rtype", 0 }, 
    6869  { "/checks", "filterset", "@filterset", 0 }, 
    6970  { "/checks", "module", "@module", 1 }, 
     
    462463    nc_attr_show(ncct, "module", node, mnode, module); 
    463464    SHOW_ATTR(target); 
     465    SHOW_ATTR(resolve_rtype); 
    464466    SHOW_ATTR(period); 
    465467    SHOW_ATTR(timeout);