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