mirror of https://git.48k.eu/ogserver
#1037 Add disk type
Add ogServer support for parsing and storing in the DB disk type data from ogClient refresh response. See also commits with #1037 in ogClient and WebConsole repo.master
parent
10c9559dfc
commit
12d8fff3ef
|
@ -321,11 +321,11 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
snprintf(cfg + strlen(cfg), sizeof(cfg) - strlen(cfg),
|
snprintf(cfg + strlen(cfg), sizeof(cfg) - strlen(cfg),
|
||||||
"disk=%s\tpar=%s\tcpt=%s\tfsi=%s\tsoi=%s\ttam=%s\tuso=%s\n",
|
"disk=%s\tpar=%s\tcpt=%s\tfsi=%s\tsoi=%s\ttam=%s\tuso=%s\tdtype=%s\n",
|
||||||
disks[i].disk, disks[i].number,
|
disks[i].disk, disks[i].number,
|
||||||
disks[i].code, disks[i].filesystem,
|
disks[i].code, disks[i].filesystem,
|
||||||
disks[i].os, disks[i].size,
|
disks[i].os, disks[i].size,
|
||||||
disks[i].used_size);
|
disks[i].used_size, disks[i].disk_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < OG_PARTITION_MAX; i++) {
|
for (i = 0; i < OG_PARTITION_MAX; i++) {
|
||||||
|
|
|
@ -120,6 +120,9 @@ int og_json_parse_partition(json_t *element, struct og_partition *part,
|
||||||
} else if (!strcmp(key, "disk")) {
|
} else if (!strcmp(key, "disk")) {
|
||||||
err = og_json_parse_string(value, &part->disk);
|
err = og_json_parse_string(value, &part->disk);
|
||||||
flags |= OG_PARAM_PART_DISK;
|
flags |= OG_PARAM_PART_DISK;
|
||||||
|
} else if (!strcmp(key, "disk_type")) {
|
||||||
|
err = og_json_parse_string(value, &part->disk_type);
|
||||||
|
flags |= OG_PARAM_PART_DISK_TYPE;
|
||||||
} else if (!strcmp(key, "os")) {
|
} else if (!strcmp(key, "os")) {
|
||||||
err = og_json_parse_string(value, &part->os);
|
err = og_json_parse_string(value, &part->os);
|
||||||
flags |= OG_PARAM_PART_OS;
|
flags |= OG_PARAM_PART_OS;
|
||||||
|
|
|
@ -18,9 +18,11 @@ int og_json_parse_bool(json_t *element, bool *value);
|
||||||
#define OG_PARAM_PART_DISK (1UL << 5)
|
#define OG_PARAM_PART_DISK (1UL << 5)
|
||||||
#define OG_PARAM_PART_OS (1UL << 6)
|
#define OG_PARAM_PART_OS (1UL << 6)
|
||||||
#define OG_PARAM_PART_USED_SIZE (1UL << 7)
|
#define OG_PARAM_PART_USED_SIZE (1UL << 7)
|
||||||
|
#define OG_PARAM_PART_DISK_TYPE (1UL << 8)
|
||||||
|
|
||||||
struct og_partition {
|
struct og_partition {
|
||||||
const char *disk;
|
const char *disk;
|
||||||
|
const char *disk_type;
|
||||||
const char *number;
|
const char *number;
|
||||||
const char *code;
|
const char *code;
|
||||||
const char *size;
|
const char *size;
|
||||||
|
|
|
@ -47,8 +47,8 @@
|
||||||
bool actualizaConfiguracion(struct og_dbi *dbi, char *cfg, int ido)
|
bool actualizaConfiguracion(struct og_dbi *dbi, char *cfg, int ido)
|
||||||
{
|
{
|
||||||
int lon, p, c,i, dato, swu, idsoi, idsfi,k;
|
int lon, p, c,i, dato, swu, idsoi, idsfi,k;
|
||||||
char *ptrPar[MAXPAR], *ptrCfg[7], *ptrDual[2], tbPar[LONSTD];
|
char *ptrPar[MAXPAR], *ptrCfg[8], *ptrDual[2], tbPar[LONSTD];
|
||||||
char *ser, *disk, *par, *cpt, *sfi, *soi, *tam, *uso; // Parametros de configuración.
|
char *ser, *disk, *disk_type, *par, *cpt, *sfi, *soi, *tam, *uso; // Parametros de configuración.
|
||||||
dbi_result result, result_update;
|
dbi_result result, result_update;
|
||||||
const char *msglog;
|
const char *msglog;
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ bool actualizaConfiguracion(struct og_dbi *dbi, char *cfg, int ido)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Distribución de particionado.
|
// Distribución de particionado.
|
||||||
disk = par = cpt = sfi = soi = tam = uso = NULL;
|
disk = disk_type = par = cpt = sfi = soi = tam = uso = NULL;
|
||||||
|
|
||||||
splitCadena(ptrDual, ptrCfg[0], '=');
|
splitCadena(ptrDual, ptrCfg[0], '=');
|
||||||
disk = ptrDual[1]; // Número de disco
|
disk = ptrDual[1]; // Número de disco
|
||||||
|
@ -118,6 +118,12 @@ bool actualizaConfiguracion(struct og_dbi *dbi, char *cfg, int ido)
|
||||||
splitCadena(ptrDual, ptrCfg[6], '=');
|
splitCadena(ptrDual, ptrCfg[6], '=');
|
||||||
uso = ptrDual[1]; // Porcentaje de uso del S.F.
|
uso = ptrDual[1]; // Porcentaje de uso del S.F.
|
||||||
|
|
||||||
|
k = splitCadena(ptrDual, ptrCfg[7], '=');
|
||||||
|
if (k == 2)
|
||||||
|
disk_type = ptrDual[1];
|
||||||
|
else
|
||||||
|
disk_type = NULL;
|
||||||
|
|
||||||
lon += sprintf(tbPar + lon, "(%s, %s),", disk, par);
|
lon += sprintf(tbPar + lon, "(%s, %s),", disk, par);
|
||||||
|
|
||||||
result = dbi_conn_queryf(dbi->conn,
|
result = dbi_conn_queryf(dbi->conn,
|
||||||
|
@ -133,9 +139,9 @@ bool actualizaConfiguracion(struct og_dbi *dbi, char *cfg, int ido)
|
||||||
}
|
}
|
||||||
if (!dbi_result_next_row(result)) {
|
if (!dbi_result_next_row(result)) {
|
||||||
result_update = dbi_conn_queryf(dbi->conn,
|
result_update = dbi_conn_queryf(dbi->conn,
|
||||||
"INSERT INTO ordenadores_particiones(idordenador,numdisk,numpar,codpar,tamano,uso,idsistemafichero,idnombreso,idimagen)"
|
"INSERT INTO ordenadores_particiones(idordenador,numdisk,disk_type,numpar,codpar,tamano,uso,idsistemafichero,idnombreso,idimagen)"
|
||||||
" VALUES(%d,%s,%s,0x%s,%s,%s,%d,%d,0)",
|
" VALUES(%d,%s,'%s',%s,0x%s,%s,%s,%d,%d,0)",
|
||||||
ido, disk, par, cpt, tam, uso, idsfi, idsoi);
|
ido, disk, disk_type, par, cpt, tam, uso, idsfi, idsoi);
|
||||||
if (!result_update) {
|
if (!result_update) {
|
||||||
dbi_conn_error(dbi->conn, &msglog);
|
dbi_conn_error(dbi->conn, &msglog);
|
||||||
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
|
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
|
||||||
|
|
38
src/schema.c
38
src/schema.c
|
@ -178,12 +178,50 @@ err_no_trans:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int og_dbi_schema_v3(struct og_dbi *dbi)
|
||||||
|
{
|
||||||
|
const char *msglog, *command;
|
||||||
|
dbi_result result, result_alter;
|
||||||
|
|
||||||
|
result = dbi_conn_query(dbi->conn,
|
||||||
|
"ALTER TABLE ordenadores_particiones "
|
||||||
|
"ADD disk_type VARCHAR(32) DEFAULT NULL "
|
||||||
|
"AFTER numdisk;");
|
||||||
|
|
||||||
|
while (dbi_result_next_row(result)) {
|
||||||
|
command = dbi_result_get_string(result, "cmd");
|
||||||
|
|
||||||
|
syslog(LOG_DEBUG, "Adding disk type: %s\n", command);
|
||||||
|
result_alter = dbi_conn_query(dbi->conn, command);
|
||||||
|
if (!result_alter) {
|
||||||
|
dbi_conn_error(dbi->conn, &msglog);
|
||||||
|
syslog(LOG_INFO, "Error when adding disk type (%s:%d) %s\n",
|
||||||
|
__func__, __LINE__, msglog);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
dbi_result_free(result_alter);
|
||||||
|
}
|
||||||
|
dbi_result_free(result);
|
||||||
|
|
||||||
|
result = dbi_conn_query(dbi->conn, "UPDATE version SET version = 3");
|
||||||
|
if (!result) {
|
||||||
|
dbi_conn_error(dbi->conn, &msglog);
|
||||||
|
syslog(LOG_INFO, "Could not update version row (%s:%d) %s\n",
|
||||||
|
__func__, __LINE__, msglog);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
dbi_result_free(result);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static struct og_schema_version {
|
static struct og_schema_version {
|
||||||
int version;
|
int version;
|
||||||
int (*update)(struct og_dbi *dbi);
|
int (*update)(struct og_dbi *dbi);
|
||||||
} schema_version[] = {
|
} schema_version[] = {
|
||||||
{ .version = 1, .update = og_dbi_schema_v1 },
|
{ .version = 1, .update = og_dbi_schema_v1 },
|
||||||
{ .version = 2, .update = og_dbi_schema_v2 },
|
{ .version = 2, .update = og_dbi_schema_v2 },
|
||||||
|
{ .version = 3, .update = og_dbi_schema_v3 },
|
||||||
{ 0, NULL },
|
{ 0, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue