| 814 | |
| 815 | |
| 816 | /* |
| 817 | * rrdMibsUpdate |
| 818 | */ |
| 819 | short rrdMibsUpdate(int index) |
| 820 | { |
| 821 | int i, j, k = 0; |
| 822 | int rrd_update_er_ct = 0; |
| 823 | int rrd_update_ok_ct = 0; |
| 824 | int rrd_already_created_ct = 0; |
| 825 | int rrd_create_er_ct = 0; |
| 826 | int rrd_create_ok_ct = 0; |
| 827 | static char buf[2048]; |
| 828 | static char name[2048]; |
| 829 | static char createstr[2048]; |
| 830 | char *opt[27]; |
| 831 | char *optUpdate[3]; |
| 832 | FILE *fp; |
| 833 | static time_t now, now2; |
| 834 | |
| 835 | now = time((time_t *)NULL); |
| 836 | for (k=0; k<strlen(name); k++) {name[k] = '\0';} |
| 837 | for (k=0; k<strlen(buf); k++) {buf[k] = '\0';} |
| 838 | strcat(name, MIB_RRD_LOCATION); |
| 839 | strcat(name, GLOBAL_MIB_RRD_FILE); |
| 840 | if ( (fp=fopen(name,"r")) == NULL ){ |
| 841 | opt[0]= (char *) malloc((strlen(RRD_PARAM_MIB_0) + 1) * sizeof(char)); |
| 842 | strcpy(opt[0], RRD_PARAM_MIB_0); |
| 843 | opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); |
| 844 | strcpy(opt[1], name); |
| 845 | opt[2]= (char *) malloc((strlen(RRD_PARAM_MIB_1) + 1) * sizeof(char)); |
| 846 | strcpy(opt[2], RRD_PARAM_MIB_1); |
| 847 | opt[3]= (char *) malloc((strlen(RRD_PARAM_MIB_2) + 1) * sizeof(char)); |
| 848 | strcpy(opt[3], RRD_PARAM_MIB_2); |
| 849 | opt[4]= (char *) malloc((strlen(RRD_PARAM_MIB_3) + 1) * sizeof(char)); |
| 850 | strcpy(opt[4], RRD_PARAM_MIB_3); |
| 851 | opt[5]= (char *) malloc((strlen(RRD_PARAM_MIB_4) + 1) * sizeof(char)); |
| 852 | strcpy(opt[5], RRD_PARAM_MIB_4); |
| 853 | opt[6]= (char *) malloc((strlen(RRD_PARAM_MIB_5) + 1) * sizeof(char)); |
| 854 | strcpy(opt[6], RRD_PARAM_MIB_5); |
| 855 | opt[7]= (char *) malloc((strlen(RRD_PARAM_MIB_6) + 1) * sizeof(char)); |
| 856 | strcpy(opt[7], RRD_PARAM_MIB_6); |
| 857 | opt[8]= (char *) malloc((strlen(RRD_PARAM_MIB_7) + 1) * sizeof(char)); |
| 858 | strcpy(opt[8], RRD_PARAM_MIB_7); |
| 859 | opt[9]= (char *) malloc((strlen(RRD_PARAM_MIB_8) + 1) * sizeof(char)); |
| 860 | strcpy(opt[9], RRD_PARAM_MIB_8); |
| 861 | opt[10]= (char *) malloc((strlen(RRD_PARAM_MIB_9) + 1) * sizeof(char)); |
| 862 | strcpy(opt[10], RRD_PARAM_MIB_9); |
| 863 | opt[11]= (char *) malloc((strlen(RRD_PARAM_MIB_10) + 1) * sizeof(char)); |
| 864 | strcpy(opt[11], RRD_PARAM_MIB_10); |
| 865 | opt[12]= (char *) malloc((strlen(RRD_PARAM_MIB_11) + 1) * sizeof(char)); |
| 866 | strcpy(opt[12], RRD_PARAM_MIB_11); |
| 867 | opt[13]= (char *) malloc((strlen(RRD_PARAM_MIB_12) + 1) * sizeof(char)); |
| 868 | strcpy(opt[13], RRD_PARAM_MIB_12); |
| 869 | opt[14]= (char *) malloc((strlen(RRD_PARAM_MIB_13) + 1) * sizeof(char)); |
| 870 | strcpy(opt[14], RRD_PARAM_MIB_13); |
| 871 | opt[15]= (char *) malloc((strlen(RRD_PARAM_MIB_14) + 1) * sizeof(char)); |
| 872 | strcpy(opt[15], RRD_PARAM_MIB_14); |
| 873 | opt[16]= (char *) malloc((strlen(RRD_PARAM_MIB_15) + 1) * sizeof(char)); |
| 874 | strcpy(opt[16], RRD_PARAM_MIB_15); |
| 875 | opt[17]= (char *) malloc((strlen(RRD_PARAM_MIB_16) + 1) * sizeof(char)); |
| 876 | strcpy(opt[17], RRD_PARAM_MIB_16); |
| 877 | opt[18]= (char *) malloc((strlen(RRD_PARAM_MIB_17) + 1) * sizeof(char)); |
| 878 | strcpy(opt[18], RRD_PARAM_MIB_17); |
| 879 | opt[19]= (char *) malloc((strlen(RRD_PARAM_MIB_18) + 1) * sizeof(char)); |
| 880 | strcpy(opt[19], RRD_PARAM_MIB_18); |
| 881 | opt[20]= (char *) malloc((strlen(RRD_PARAM_MIB_19) + 1) * sizeof(char)); |
| 882 | strcpy(opt[20], RRD_PARAM_MIB_19); |
| 883 | opt[21]= (char *) malloc((strlen(RRD_PARAM_MIB_20) + 1) * sizeof(char)); |
| 884 | strcpy(opt[21], RRD_PARAM_MIB_20); |
| 885 | opt[22]= (char *) malloc((strlen(RRD_PARAM_MIB_21) + 1) * sizeof(char)); |
| 886 | strcpy(opt[22], RRD_PARAM_MIB_21); |
| 887 | opt[23]= (char *) malloc((strlen(RRD_PARAM_MIB_22) + 1) * sizeof(char)); |
| 888 | strcpy(opt[23], RRD_PARAM_MIB_22); |
| 889 | optind = opterr = 0; |
| 890 | rrd_clear_error(); |
| 891 | if ( rrd_create(24,opt) < 0) { |
| 892 | syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); |
| 893 | rrd_create_er_ct++; |
| 894 | } else { |
| 895 | rrd_create_ok_ct++; |
| 896 | } |
| 897 | for ( k=0; k<24; k++) { |
| 898 | free(opt[k]); |
| 899 | opt[k] = NULL; |
| 900 | } |
| 901 | }else{ |
| 902 | fclose(fp); |
| 903 | rrd_already_created_ct++; |
| 904 | snprintf(buf, |
| 905 | 2048, |
| 906 | "%lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu", |
| 907 | now-300, /* or ctime(&now) with %s */ |
| 908 | shmForAgg->myMIB[index].ipPacketNb, |
| 909 | shmForAgg->myMIB[index].udpPacketNb, |
| 910 | shmForAgg->myMIB[index].v9PacketNb, |
| 911 | shmForAgg->myMIB[index].v9UnSeqNb, |
| 912 | shmForAgg->myMIB[index].flowSetNb, |
| 913 | shmForAgg->myMIB[index].dataFlowSetNb, |
| 914 | shmForAgg->myMIB[index].defFlowSetNb, |
| 915 | shmForAgg->myMIB[index].optDataFlowSetNb, |
| 916 | shmForAgg->myMIB[index].optDefFlowSetNb, |
| 917 | shmForAgg->myMIB[index].flowNb, |
| 918 | shmForAgg->myMIB[index].realFlowNb |
| 919 | ); |
| 920 | fprintf(stderr,"\n%s\n",buf); |
| 921 | optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); |
| 922 | strcpy(optUpdate[0], RRD_UPDATE_0); |
| 923 | optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); |
| 924 | strcpy(optUpdate[1], name); |
| 925 | optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); |
| 926 | strcpy(optUpdate[2], buf); |
| 927 | optind = opterr = 0; |
| 928 | rrd_clear_error(); |
| 929 | if ( rrd_update(3, optUpdate) < 0 ) { |
| 930 | syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); |
| 931 | rrd_update_er_ct++; |
| 932 | } else { |
| 933 | rrd_update_ok_ct++; |
| 934 | } |
| 935 | for ( k=0; k<3; k++) { |
| 936 | free(optUpdate[k]); |
| 937 | optUpdate[k] = NULL; |
| 938 | } |
| 939 | } |
| 940 | shmForAgg->myMIB[index].ipPacketNb = 0; |
| 941 | shmForAgg->myMIB[index].udpPacketNb = 0; |
| 942 | shmForAgg->myMIB[index].v9PacketNb = 0; |
| 943 | shmForAgg->myMIB[index].v9UnSeqNb = 0; |
| 944 | shmForAgg->myMIB[index].flowSetNb = 0; |
| 945 | shmForAgg->myMIB[index].dataFlowSetNb = 0; |
| 946 | shmForAgg->myMIB[index].defFlowSetNb = 0; |
| 947 | shmForAgg->myMIB[index].optDataFlowSetNb = 0; |
| 948 | shmForAgg->myMIB[index].optDefFlowSetNb = 0; |
| 949 | shmForAgg->myMIB[index].flowNb = 0; |
| 950 | shmForAgg->myMIB[index].realFlowNb = 0; |
| 951 | return 1; |
| 952 | } |