1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the License). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/CDDL.txt 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/CDDL.txt. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets [] replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 1998-2003 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * 26 * apache_probe.c - Probe for highly available apache 27 */ 28 29 #pragma ident "@(#)apache_probe.c 1.36 07/06/06 SMI" 30 31 #include <stdio.h> 32 #include <stdlib.h> 33 #include <sys/time.h> 34 #include <rgm/libdsdev.h> 35 #include "apache.h" 36 37 int 38 main(int argc, char *argv[]) 39 { 40 scds_handle_t scds_handle; 41 scha_err_t err = SCHA_ERR_NOERR; 42 int timeout, probe_interval, 43 port, i, probe_result; 44 hrtime_t ht1, ht2; 45 long dt; 46 char *hostname = NULL; 47 scds_netaddr_list_t *netaddr; 48 scha_extprop_value_t *urilist = NULL; 49 scha_str_array_t *uris = NULL; 50 51 if (scds_initialize(&scds_handle, argc, argv) != SCHA_ERR_NOERR) 52 return (1); 53 54 /* Get the ip addresses available for this resource */ 55 err = scds_get_netaddr_list(scds_handle, &netaddr); 56 if (err != SCHA_ERR_NOERR) { 57 scds_syslog(LOG_ERR, 58 "Error in trying to access the " 59 "configured network resources : %s.", 60 scds_error_string(err)); 61 scds_close(&scds_handle); 62 return (1); 63 } 64 65 /* Return an error if there are no network resources */ 66 if (netaddr == NULL || netaddr->num_netaddrs == 0) { 67 scds_syslog(LOG_ERR, 68 "No network address resource in resource group."); 69 return (1); 70 } 71 72 /* Retrieve the list of uris that we were told to probe */ 73 err = scds_get_ext_property(scds_handle, "Monitor_Uri_List", 74 SCHA_PTYPE_STRINGARRAY, &urilist); 75 if ((err != SCHA_ERR_NOERR) && (err != SCHA_ERR_PROP)) { 76 /* failed with something other than SCHA_ERR_PROP */ 77 scds_syslog(LOG_ERR, 78 "Failed to retrieve the " 79 "property %s: %s.", 80 "Monitor_Uri_List", scds_error_string(err)); 81 return (1); 82 } 83 84 if (urilist != NULL) { 85 uris = urilist->val.val_strarray; 86 } 87 88 /* 89 * Get the timeout from the extension props. This means that 90 * each probe iteration will get a full timeout on each network 91 * resource without chopping up the timeout between all of the 92 * network resources configured for this resource. 93 */ 94 timeout = scds_get_ext_probe_timeout(scds_handle); 95 96 /* Get interval for sleep between probes */ 97 probe_interval = scds_get_rs_thorough_probe_interval(scds_handle); 98 99 for (;;) { 100 101 /* 102 * sleep for a duration of thorough_probe_interval between 103 * successive probes. 104 */ 105 (void) scds_fm_sleep(scds_handle, probe_interval); 106 107 /* 108 * Now probe all netaddress we use. 109 * For each of the netaddress that is probed, 110 * compute the failure history. 111 */ 112 probe_result = 0; 113 /* 114 * Iterate through all the netaddrs calling svc_probe() 115 */ 116 for (i = 0; i < netaddr->num_netaddrs; i++) { 117 /* 118 * Grab the hostname and port on which the 119 * health has to be monitored. 120 */ 121 hostname = netaddr->netaddrs[i].hostname; 122 port = netaddr->netaddrs[i].port_proto.port; 123 ht1 = gethrtime(); /* Latch probe start time */ 124 125 probe_result = svc_probe(scds_handle, hostname, port, 126 timeout, B_TRUE); 127 128 ht2 = gethrtime(); 129 130 /* Convert to milliseconds */ 131 dt = (long)((ht2 - ht1) / 1e6); 132 133 /* 134 * Compute failure history and take action if needed 135 */ 136 (void) scds_fm_action(scds_handle, probe_result, dt); 137 138 } /* Each netaddr */ 139 140 /* probe all uris (if any) that were supplied */ 141 if (uris) { 142 for (i = 0; i < (int)uris->array_cnt; i++) { 143 ht1 = gethrtime(); 144 probe_result = probe_uri(scds_handle, 145 uris->str_array[i], timeout, B_TRUE); 146 ht2 = gethrtime(); 147 148 dt = (long)((ht2 - ht1) / 1e6); 149 150 (void) scds_fm_action(scds_handle, probe_result, 151 dt); 152 } 153 } 154 155 } /* Keep probing forever */ 156 } 157