00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <jsoc_main.h>
00018 #include <sum_rpc.h>
00019 #include <cmdparams.h>
00020 #include <drms.h>
00021 #include <drms_names.h>
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <ctype.h>
00025 #include <strings.h>
00026 #include <soi_key.h>
00027 #include <sys/time.h>
00028 #include <sys/types.h>
00029 #include <sys/stat.h>
00030 #include <unistd.h>
00031 #include <printk.h>
00032 #include <setjmp.h>
00033 #include "pe.h"
00034
00035 #define out_namespace "dsds"
00036
00037
00038 void printkey();
00039 int soi_errno = NO_ERROR;
00040
00041 int start_sn, end_sn, next_sn, series_num;
00042 int abort_active;
00043 int nocontrolc;
00044 int debugflg;
00045
00046 int ccactive = 0;
00047 int dbxflg = 0;
00048
00049 char a_prog[32], a_level[32], a_series[32];
00050 char line[1024];
00051 char *username;
00052 char *in_ds;
00053 KEY *dslist;
00054 KEY *alist;
00055 SUM_t *sumhandle = NULL;
00056
00057 static struct timeval TIMEOUT = { 20, 0 };
00058
00059
00060 ModuleArgs_t module_args[] = {
00061 {ARG_END}
00062 };
00063
00064 CmdParams_t cmdparams;
00065 char **argv = NULL;
00066 char *pargv[12];
00067 int argc = 0;
00068 char *module_name = "jpeq";
00069 jmp_buf env;
00070
00071
00072 void get_args(int argc, char *argv[])
00073 {
00074 int c;
00075 if(argc != 6) {
00076 printf("Usage: jsnqry -pprog -llevel -sseries -bstart_sn -eend_sn\n");
00077 printf("where: -pprog = prog is prog name eg. mdi_eof\n");
00078 printf(" -llevel = level is level name eg. lev0\n");
00079 printf(" -sseries = series is series name eg. 00022000_01h\n");
00080 printf(" For series alone wild card can be used for search eg.00022000%%\n");
00081 printf(" Note: %% is the wild card character\n");
00082 printf(" -bstart_sn -eend_sn = start_sn and end_sn are series number ranges\n");
00083 exit(1);
00084 }
00085 while(--argc > 0 && (*++argv)[0] == '-') {
00086 while( c = *++argv[0])
00087 switch (c) {
00088 case 'p':
00089 if(*++argv[0] != NULL) {
00090 strcpy((char *)a_prog, argv[0]);
00091 }
00092 while(*++argv[0] != NULL);
00093 --argv[0];
00094 break;
00095 case 'l':
00096 if(*++argv[0] != NULL) {
00097 strcpy((char *)a_level, argv[0]);
00098 }
00099 while(*++argv[0] != NULL);
00100 --argv[0];
00101 break;
00102 case 's':
00103 if(*++argv[0] != NULL) {
00104 strcpy((char *)a_series, argv[0]);
00105 }
00106 while(*++argv[0] != NULL);
00107 --argv[0];
00108 break;
00109 case 'b':
00110 if(*++argv[0] != NULL) {
00111 start_sn = atoi(argv[0]);
00112 }
00113 break;
00114 case 'e':
00115 if(*++argv[0] != NULL) {
00116 end_sn = atoi(argv[0]);
00117 }
00118 break;
00119 }
00120 }
00121 }
00122
00123
00124 char *kdatestring(void)
00125 {
00126 time_t t;
00127 char *str;
00128
00129 t = time(NULL);
00130 str = ctime(&t);
00131 str[19] = 0;
00132 return str+4;
00133 }
00134
00135
00136 int DoIt()
00137 {
00138 int wildflg = 0;
00139 int found = 0;
00140 int c, rstatus;
00141 char drmsname[128], cmd[128], buf[128], path[128], qcmd[128], rstring[128];
00142 char logfile[128];
00143 char *cptr, *cptr1;
00144 FILE *fin;
00145 DRMS_RecordSet_t *rset;
00146 DRMS_Record_t *rec;
00147 DRMS_SeriesInfo_t *seriesinfo;
00148
00149 cmdparams_get_argv(&cmdparams, &argv, &argc);
00150 for(c=0; c < argc; c++) {
00151 pargv[c] = strdup(argv[c]);
00152 }
00153 printk_set(printf, printf);
00154 if(!(username = (char *)getenv("USER"))) username = "nouser";
00155 get_args(argc, pargv);
00156 if(strchr(a_series, '%')) { wildflg = 1; }
00157
00158 sprintf(drmsname, "%s__%s__%s", a_prog, a_level, a_series);
00159 sprintf(cmd, "echo \"%s\" | sed 's/\\\./_/g' | sed 's/-/__/g'", drmsname);
00160
00161 fin = popen(cmd, "r");
00162 fgets(buf, sizeof buf, fin);
00163 fclose(fin);
00164 cptr = rindex(buf, '\n');
00165 if(cptr) *cptr = NULL;
00166
00167 if(wildflg) {
00168 sprintf(qcmd, "select seriesname from %s.drms_series where seriesname like '%s.%s'", out_namespace, out_namespace, buf);
00169 sprintf(cmd, "echo \"%s\" | psql -h hmidb jsoc", qcmd);
00170 fin = popen(cmd, "r");
00171 while(fgets(buf, sizeof buf, fin)) {
00172 if(strstr(buf, out_namespace)) {
00173 cptr = rindex(buf, '\n');
00174 if(cptr) *cptr = NULL;
00175 found = 1;
00176 break;
00177 }
00178 }
00179 if(!found) return(0);
00180 cptr = strstr(buf, "__");
00181 if(!cptr) return(1);
00182 cptr1 = strstr(cptr+2, "__");
00183 if(!cptr1) return(1);
00184 strcpy(a_series, cptr1+2);
00185 }
00186 while(1) {
00187 for(next_sn = start_sn; next_sn <= end_sn; next_sn++) {
00188 if(wildflg) {
00189 sprintf(drmsname, "%s[%d]", buf, next_sn);
00190 }
00191 else sprintf(drmsname, "%s.%s[%d]", out_namespace, buf, next_sn);
00192 rset = drms_open_records(drms_env, drmsname, &rstatus);
00193 if(rstatus) {
00194 printk("Can't do drms_open_records(%s)\n", drmsname);
00195 continue;
00196 }
00197 if(!rset || rset->n == 0) {
00198
00199 continue;
00200 }
00201
00202
00203
00204
00205
00206 printk("prog:%s,level:%s,series:%s[%d]\n",
00207 a_prog, a_level, a_series, next_sn);
00208 drms_close_record(rset->records[0], DRMS_FREE_RECORD);
00209 }
00210 if(wildflg) {
00211 if(!fgets(buf, sizeof buf, fin)) {
00212 fclose(fin);
00213 return(0);
00214 }
00215 if(!strstr(buf, out_namespace)) {
00216 fclose(fin);
00217 return(0);
00218 }
00219 cptr = rindex(buf, '\n');
00220 if(cptr) *cptr = NULL;
00221 cptr = strstr(buf, "__");
00222 if(!cptr) return(1);
00223 cptr1 = strstr(cptr+2, "__");
00224 if(!cptr1) return(1);
00225 strcpy(a_series, cptr1+2);
00226 }
00227 else return(0);
00228 }
00229
00230 }