示例#1
0
static void my_exec(RESULT * result, RESULT * module, RESULT * function, RESULT * arg)
{
    /* Fixme: a plugin should be able to accept any number of arguments, don't know how
       to code that (yet) */
    const char *args[] = { R2S(arg) };
    pyt_exec_str(result, R2S(module), R2S(function), 1, args);
}
示例#2
0
static void my_proc_stat(RESULT * result, const int argc, RESULT * argv[])
{
    char *string;
    double number;

    if (parse_proc_stat() < 0) {
	SetResult(&result, R_STRING, "");
	return;
    }

    switch (argc) {
    case 1:
	string = hash_get(&Stat, R2S(argv[0]), NULL);
	if (string == NULL)
	    string = "";
	SetResult(&result, R_STRING, string);
	break;
    case 2:
	number = hash_get_delta(&Stat, R2S(argv[0]), NULL, R2N(argv[1]));
	SetResult(&result, R_NUMBER, &number);
	break;
    default:
	error("proc_stat(): wrong number of parameters");
	SetResult(&result, R_STRING, "");
    }
}
示例#3
0
static void my_uname(RESULT * result, RESULT * arg1)
{
    struct utsname utsbuf;
    char *key, *value;

    key = R2S(arg1);

    if (uname(&utsbuf) != 0) {
	error("uname() failed: %s", strerror(errno));
	SetResult(&result, R_STRING, "");
	return;
    }

    if (strcasecmp(key, "sysname") == 0) {
	value = utsbuf.sysname;
    } else if (strcasecmp(key, "nodename") == 0) {
	value = utsbuf.nodename;
    } else if (strcasecmp(key, "release") == 0) {
	value = utsbuf.release;
    } else if (strcasecmp(key, "version") == 0) {
	value = utsbuf.version;
    } else if (strcasecmp(key, "machine") == 0) {
	value = utsbuf.machine;
#if defined(_GNU_SOURCE) && ! defined(__APPLE__) && ! defined(__CYGWIN__)
    } else if (strcasecmp(key, "domainname") == 0) {
	value = utsbuf.domainname;
#endif
    } else {
	error("uname: unknown field '%s'", key);
	value = "";
    }

    SetResult(&result, R_STRING, value);
}
示例#4
0
static void my_MySQLquery(RESULT * result, RESULT * query)
{
    char *q;
    double value;
    MYSQL_RES *res;
    MYSQL_ROW row = NULL;

    if (configure_mysql() < 0) {
	value = -1;
	SetResult(&result, R_NUMBER, &value);
	return;
    }

    q = R2S(query);

    /* mysql_ping(MYSQL *mysql) checks whether the connection to the server is working. */
    /* If it has gone down, an automatic reconnection is attempted. */
    mysql_ping(&conex);
    if (mysql_real_query(&conex, q, (unsigned int) strlen(q))) {
	error("[MySQL] query error: %s", mysql_error(&conex));
	value = -1;
    } else {
	/* We don't use res=mysql_use_result();  because mysql_num_rows() will not */
	/* return the correct value until all the rows in the result set have been retrieved */
	/* with mysql_fetch_row(), so we use res=mysql_store_result(); instead */
	res = mysql_store_result(&conex);
	row = mysql_fetch_row(res);
	mysql_free_result(res);
    }

    SetResult(&result, R_STRING, row[0]);
}
示例#5
0
static void wireless_level(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_LEVEL, get_stats(dev, KEY_LEVEL));
}
示例#6
0
static void wireless_frequency(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_FREQUENCY, get_frequency(dev, KEY_FREQUENCY));
}
示例#7
0
static void wireless_sec_mode(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_SEC_MODE, get_sec_mode(dev, KEY_SEC_MODE));
}
示例#8
0
static void wireless_essid(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_ESSID, get_essid(dev, KEY_ESSID));
}
示例#9
0
static void wireless_sensitivity(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_SENS, get_sens(dev, KEY_SENS));
}
示例#10
0
static void wireless_noise(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_NOISE, get_stats(dev, KEY_NOISE));
}
示例#11
0
static void wireless_bitrate(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_BIT_RATE, get_bitrate(dev, KEY_BIT_RATE));
}
示例#12
0
static void wireless_protocol(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_PROTO, get_ifname(NULL, dev));
}
示例#13
0
static void wireless_quality(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_QUALITY, get_stats(dev, KEY_QUALITY));
}
示例#14
0
char *P2S(PROPERTY * prop)
{
    if (prop == NULL) {
	error("Property: internal error: NULL property");
	return NULL;
    }
    return R2S(&prop->result);
}
示例#15
0
static void my_length(RESULT * result, RESULT * arg1)
{
    /* Note #1: value *must* be double!  */
    /* Note #2: R2S stands for 'Result to String' */
    double value = strlen(R2S(arg1));

    /* store result */
    SetResult(&result, R_NUMBER, &value);
}
示例#16
0
static void my_statfs(RESULT * result, RESULT * arg1, RESULT * arg2)
{
    struct statfs buf;
    char *path, *key;
    double value;

    path = R2S(arg1);
    key = R2S(arg2);

    if (statfs(path, &buf) != 0) {
	error("statfs(%s) failed: %s", path, strerror(errno));
	SetResult(&result, R_STRING, "");
	return;
    }

    if (strcasecmp(key, "type") == 0) {
	value = buf.f_type;
    } else if (strcasecmp(key, "bsize") == 0) {
	value = buf.f_bsize;
    } else if (strcasecmp(key, "blocks") == 0) {
	value = buf.f_blocks;
    } else if (strcasecmp(key, "bfree") == 0) {
	value = buf.f_bfree;
    } else if (strcasecmp(key, "bavail") == 0) {
	value = buf.f_bavail;
    } else if (strcasecmp(key, "files") == 0) {
	value = buf.f_files;
    } else if (strcasecmp(key, "ffree") == 0) {
	value = buf.f_ffree;
#if 0
    } else if (strcasecmp(key, "fsid") == 0) {
	value = buf.f_fsid;
#endif
    } else if (strcasecmp(key, "namelen") == 0) {
	value = buf.f_namelen;
    } else {
	error("statfs: unknown field '%s'", key);
	value = -1;
    }

    SetResult(&result, R_NUMBER, &value);
}
示例#17
0
static void my_cpu(RESULT * result, RESULT * arg1, RESULT * arg2)
{
    char *key;
    int delay;
    double value;
    double cpu_user, cpu_nice, cpu_system, cpu_idle, cpu_total;
    double cpu_iow, cpu_irq, cpu_sirq;

    if (parse_proc_stat() < 0) {
	SetResult(&result, R_STRING, "");
	return;
    }

    key = R2S(arg1);
    delay = R2N(arg2);

    cpu_user = hash_get_delta(&Stat, "cpu.user", NULL, delay);
    cpu_nice = hash_get_delta(&Stat, "cpu.nice", NULL, delay);
    cpu_system = hash_get_delta(&Stat, "cpu.system", NULL, delay);
    cpu_idle = hash_get_delta(&Stat, "cpu.idle", NULL, delay);

    /* new fields for kernel 2.6 */
    /* even if we dont have this param (ie kernel 2.4) */
    /* the return is 0.0 and not change the results */
    cpu_iow = hash_get_delta(&Stat, "cpu.iow", NULL, delay);
    cpu_irq = hash_get_delta(&Stat, "cpu.irq", NULL, delay);
    cpu_sirq = hash_get_delta(&Stat, "cpu.sirq", NULL, delay);

    cpu_total = cpu_user + cpu_nice + cpu_system + cpu_idle + cpu_iow + cpu_irq + cpu_sirq;

    if (strcasecmp(key, "user") == 0)
	value = cpu_user;
    else if (strcasecmp(key, "nice") == 0)
	value = cpu_nice;
    else if (strcasecmp(key, "system") == 0)
	value = cpu_system;
    else if (strcasecmp(key, "idle") == 0)
	value = cpu_idle;
    else if (strcasecmp(key, "iowait") == 0)
	value = cpu_iow;
    else if (strcasecmp(key, "irq") == 0)
	value = cpu_irq;
    else if (strcasecmp(key, "softirq") == 0)
	value = cpu_sirq;
    else if (strcasecmp(key, "busy") == 0)
	value = cpu_total - cpu_idle;

    if (cpu_total > 0.0)
	value = 100 * value / cpu_total;
    else
	value = 0.0;

    SetResult(&result, R_NUMBER, &value);
}
示例#18
0
static void my_disk(RESULT * result, RESULT * arg1, RESULT * arg2, RESULT * arg3)
{
    char *dev, *key, buffer[32];
    int delay;
    double value;

    if (parse_proc_stat() < 0) {
	SetResult(&result, R_STRING, "");
	return;
    }

    dev = R2S(arg1);
    key = R2S(arg2);
    delay = R2N(arg3);

    qprintf(buffer, sizeof(buffer), "disk_io\\.%s\\.%s", dev, key);
    value = hash_get_regex(&Stat, buffer, NULL, delay);

    SetResult(&result, R_NUMBER, &value);
}
示例#19
0
static void my_imon_quantity(RESULT * result, RESULT * arg1, RESULT * arg2)
{
    char *val;
    char buf[256];

    if (configure_imon() < 0) {
	SetResult(&result, R_STRING, "");
	return;
    }

    if (parse_imon_quantity(R2S(arg1)) < 0) {
	SetResult(&result, R_STRING, "");
	return;
    }

    qprintf(buf, sizeof(buf), "quantity %s %s", R2S(arg1), R2S(arg2));

    val = hash_get(&IMON, buf, NULL);
    if (val == NULL)
	val = "";
    SetResult(&result, R_STRING, val);
}
示例#20
0
static void my_imon_status(RESULT * result, RESULT * arg1)
{
    char *val;
    char buf[256];

    if (configure_imon() < 0) {
	SetResult(&result, R_NUMBER, "-1");
	return;
    }

    if (parse_imon_status(R2S(arg1)) < 0) {
	SetResult(&result, R_STRING, "-1");
	return;
    }

    qprintf(buf, sizeof(buf), "status %s", R2S(arg1));

    val = hash_get(&IMON, buf, NULL);
    if (val == NULL)
	val = "-1";
    SetResult(&result, R_STRING, val);
}
示例#21
0
static void my_apm(RESULT * result, RESULT * arg1)
{
    char *val;

    if (parse_proc_apm() < 0) {
	SetResult(&result, R_STRING, "");
	return;
    }

    val = hash_get(&APM, R2S(arg1), NULL);
    if (val == NULL)
	val = "";

    SetResult(&result, R_STRING, val);
}
示例#22
0
static void my_xmms(RESULT * result, RESULT * arg1)
{
    char *key, *val;

    if (parse_xmms_info() < 0) {
	SetResult(&result, R_STRING, "");
	return;
    }

    key = R2S(arg1);
    val = hash_get(&xmms, key, NULL);
    if (val == NULL)
	val = "";

    SetResult(&result, R_STRING, val);
}
示例#23
0
static void my_telmon(RESULT * result, RESULT * arg1)
{
    char *val = NULL;

    if (configure_telmon() < 0) {
	SetResult(&result, R_STRING, "");
	return;
    }

    if (parse_telmon() < 0) {
	SetResult(&result, R_STRING, "");
	return;
    }

    val = hash_get(&TELMON, R2S(arg1), NULL);
    if (val == NULL)
	val = "";
    SetResult(&result, R_STRING, val);
}
示例#24
0
static void my_imon(RESULT * result, RESULT * arg1)
{
    char *val;
    char *cmd;

    if (configure_imon() < 0) {
	SetResult(&result, R_STRING, "");
	return;
    }

    cmd = R2S(arg1);
    if (parse_imon(cmd) < 0) {
	SetResult(&result, R_STRING, "");
	return;
    }

    val = hash_get(&IMON, cmd, NULL);
    if (val == NULL)
	val = "";
    SetResult(&result, R_STRING, val);
}
示例#25
0
static void my_upcase(RESULT * result, RESULT * arg1)
{
    char *value, *p;

    /* create a local copy of the argument */
    /* Do *NOT* try to modify the original string! */
    value = strdup(R2S(arg1));

    /* process the string */
    for (p = value; *p != '\0'; p++)
	*p = toupper(*p);

    /* store result */
    /* when called with R_STRING, it assumes the */
    /* next parameter to be a pointer to a string */
    /* 'value' is already a char*, so use 'value', not '&value' */
    SetResult(&result, R_STRING, value);

    /* free local copy again */
    /* Note that SetResult() makes its own string copy  */
    free(value);
}
示例#26
0
static void my_concat(RESULT * result, int argc, RESULT * argv[])
{
    int i, len;
    char *value, *part;

    /* start with a empty string */
    value = strdup("");

    /* process all arguments */
    for (i = 0; i < argc; i++) {
	part = R2S(argv[i]);
	len = strlen(value) + strlen(part);
	value = realloc(value, len + 1);
	strcat(value, part);
    }

    /* store result */
    SetResult(&result, R_STRING, value);

    /* free local string */
    free(value);
}
示例#27
0
static void my_uptime(RESULT * result, const int argc, RESULT * argv[])
{
    int age;
    static double uptime = 0.0;
    static struct timeval last_value;
    struct timeval now;

    if (argc > 1) {
	error("uptime(): wrong number of parameters");
	SetResult(&result, R_STRING, "");
	return;
    }

    gettimeofday(&now, NULL);

    age = (now.tv_sec - last_value.tv_sec) * 1000 + (now.tv_usec - last_value.tv_usec) / 1000;
    /* reread every 100 msec only */
    if (fd == -2 || age == 0 || age > 100) {
	uptime = getuptime();
	if (uptime < 0.0) {
	    error("parse(/proc/uptime) failed!");
	    SetResult(&result, R_STRING, "");
	    return;
	}

	last_value = now;
    }

    if (argc == 0) {
	SetResult(&result, R_NUMBER, &uptime);
    } else {
	SetResult(&result, R_STRING, struptime(uptime, R2S(argv[0])));
    }

    return;

}