Code

store: Added core support for “metrics” objects.
[sysdb.git] / src / include / core / store.h
index bad17a22be0ba523fb5deaf4044727d093c56ccd..a7d86f529df54f56c4f9328ac6068731f52a28fa 100644 (file)
@@ -46,11 +46,13 @@ extern "C" {
 enum {
        SDB_HOST = 1,
        SDB_SERVICE,
+       SDB_METRIC,
        SDB_ATTRIBUTE,
 };
 #define SDB_STORE_TYPE_TO_NAME(t) \
        (((t) == SDB_HOST) ? "host" \
                : ((t) == SDB_SERVICE) ? "service" \
+               : ((t) == SDB_METRIC) ? "metric" \
                : ((t) == SDB_ATTRIBUTE) ? "attribute" : "unknown")
 
 /*
@@ -173,6 +175,21 @@ int
 sdb_store_service_attr(const char *hostname, const char *service,
                const char *key, const sdb_data_t *value, sdb_time_t last_update);
 
+/*
+ * sdb_store_get_field:
+ * Get the value of a stored object's queryable field. The caller is
+ * responsible for freeing any dynamically allocated memory possibly stored in
+ * the returned value.
+ *
+ * Note: Retrieving the backend this way is not currently supported.
+ *
+ * Returns:
+ *  - 0 on success
+ *  - a negative value else
+ */
+int
+sdb_store_get_field(sdb_store_obj_t *obj, int field, sdb_data_t *res);
+
 /*
  * Expressions specify arithmetic expressions.
  *
@@ -195,6 +212,18 @@ typedef struct sdb_store_expr sdb_store_expr_t;
 sdb_store_expr_t *
 sdb_store_expr_create(int op, sdb_store_expr_t *left, sdb_store_expr_t *right);
 
+/*
+ * sdb_store_expr_fieldvalue:
+ * Creates an expression which evaluates to the value of the specified
+ * queryable field of a stored object.
+ *
+ * Returns:
+ *  - an expression object on success
+ *  - NULL else
+ */
+sdb_store_expr_t *
+sdb_store_expr_fieldvalue(int field);
+
 /*
  * sdb_store_expr_constvalue:
  * Creates an expression which evaluates to the specified constant value.
@@ -208,16 +237,19 @@ sdb_store_expr_constvalue(const sdb_data_t *value);
 
 /*
  * sdb_store_expr_eval:
- * Evaluate an expression and stores the result in 'res'. The result's value
- * will be allocated dynamically if necessary and, thus, should be free'd by
- * the caller (e.g. using sdb_data_free_datum);
+ * Evaluate an expression for the specified stored object and stores the
+ * result in 'res'. The result's value will be allocated dynamically if
+ * necessary and, thus, should be free'd by the caller (e.g. using
+ * sdb_data_free_datum). The object may be NULL, in which case the expression
+ * needs to evaluate to a constant value.
  *
  * Returns:
  *  - 0 on success
  *  - a negative value else
  */
 int
-sdb_store_expr_eval(sdb_store_expr_t *expr, sdb_data_t *res);
+sdb_store_expr_eval(sdb_store_expr_t *expr, sdb_store_obj_t *obj,
+               sdb_data_t *res);
 
 /*
  * Conditionals may be used to lookup hosts from the store based on a
@@ -305,6 +337,17 @@ sdb_store_ge_matcher(sdb_store_cond_t *cond);
 sdb_store_matcher_t *
 sdb_store_gt_matcher(sdb_store_cond_t *cond);
 
+/*
+ * sdb_store_parse_field_name:
+ * Parse the name of a stored object's queryable field.
+ *
+ * Returns:
+ *  - the field id on success
+ *  - a negative value else
+ */
+int
+sdb_store_parse_field_name(const char *name);
+
 /*
  * sdb_store_matcher_parse_cmp:
  * Parse a simple compare expression (<obj_type>.<attr> <op> <expression>).
@@ -359,8 +402,8 @@ sdb_store_inv_matcher(sdb_store_matcher_t *m);
  * of the matcher. Only those objects matching the filter will be considered.
  *
  * Note that the filter is applied to all object types (hosts, service,
- * attribute). Thus, any object-specific matchers are mostly unsuited for this
- * purpose and, if used, may result in unexpected behavior.
+ * metric, attribute). Thus, any object-specific matchers are mostly unsuited
+ * for this purpose and, if used, may result in unexpected behavior.
  *
  * Returns:
  *  - 1 if the object matches
@@ -410,7 +453,8 @@ sdb_store_scan(sdb_store_matcher_t *m, sdb_store_matcher_t *filter,
 enum {
        SDB_SKIP_ATTRIBUTES         = 1 << 0,
        SDB_SKIP_SERVICES           = 1 << 1,
-       SDB_SKIP_SERVICE_ATTRIBUTES = 1 << 2,
+       SDB_SKIP_METRICS            = 1 << 2,
+       SDB_SKIP_SERVICE_ATTRIBUTES = 1 << 3,
 
        SDB_SKIP_ALL                = 0xffff,
 };