30 #include "executor/spi.h" 33 #ifdef PG_MODULE_MAGIC 44 textndup (text *text_arg,
int length)
47 ret = palloc (length + 1);
48 memcpy (ret, VARDATA (text_arg), length);
63 int32 first, period, period_months, periods_offset;
67 first = PG_GETARG_INT32 (0);
68 period = PG_GETARG_INT32 (1);
69 period_months = PG_GETARG_INT32 (2);
71 if (PG_NARGS() < 4 || PG_ARGISNULL (3))
76 timezone_arg = PG_GETARG_TEXT_P (3);
77 timezone = textndup (timezone_arg, VARSIZE (timezone_arg) - VARHDRSZ);
80 if (PG_NARGS() < 5 || PG_ARGISNULL (4))
83 periods_offset = PG_GETARG_INT32 (4);
85 ret =
next_time (first, period, period_months, timezone,
89 PG_RETURN_INT32 (ret);
102 if (PG_ARGISNULL (0))
107 char *hosts, *exclude;
110 hosts_arg = PG_GETARG_TEXT_P (0);
111 hosts = textndup (hosts_arg, VARSIZE (hosts_arg) - VARHDRSZ);
112 if (PG_ARGISNULL (1))
114 exclude = palloc (1);
120 exclude_arg = PG_GETARG_TEXT_P (1);
121 exclude = textndup (exclude_arg, VARSIZE (exclude_arg) - VARHDRSZ);
126 ret = SPI_exec (
"SELECT coalesce ((SELECT value FROM meta" 127 " WHERE name = 'max_hosts')," 130 if (SPI_processed > 0 && ret > 0 && SPI_tuptable != NULL)
134 cell = SPI_getvalue (SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1);
135 elog (INFO,
"cell: %s", cell);
137 max_hosts = atoi (cell);
145 PG_RETURN_INT32 (ret);
159 if (PG_ARGISNULL (0))
160 PG_RETURN_FLOAT8 (0.0);
163 text *level_arg, *class_arg;
167 class_arg = PG_GETARG_TEXT_P (1);
168 class = textndup (class_arg, VARSIZE (class_arg) - VARHDRSZ);
170 level_arg = PG_GETARG_TEXT_P (0);
171 level = textndup (level_arg, VARSIZE (level_arg) - VARHDRSZ);
177 PG_RETURN_FLOAT8 (severity);
191 if (PG_ARGISNULL (0))
192 PG_RETURN_FLOAT8 (0.0);
195 text *level_arg, *class_arg;
199 class_arg = PG_GETARG_TEXT_P (1);
200 class = textndup (class_arg, VARSIZE (class_arg) - VARHDRSZ);
202 level_arg = PG_GETARG_TEXT_P (0);
203 level = textndup (level_arg, VARSIZE (level_arg) - VARHDRSZ);
209 PG_RETURN_FLOAT8 (severity);
223 if (PG_ARGISNULL (0))
225 else if (PG_ARGISNULL (1))
229 float8 arg_one, arg_two;
231 arg_one = PG_GETARG_FLOAT8 (0);
232 arg_two = PG_GETARG_FLOAT8 (1);
234 PG_RETURN_BOOL (arg_one == arg_two);
236 PG_RETURN_BOOL (arg_one >= arg_two);
250 if (PG_ARGISNULL (0))
258 type_arg = PG_GETARG_TEXT_P (0);
259 type = textndup (type_arg, VARSIZE (type_arg) - VARHDRSZ);
264 PG_RETURN_BOOL (ret);
278 if (PG_ARGISNULL (0) || PG_ARGISNULL (1))
282 text *string_arg, *regexp_arg;
283 char *string, *regexp;
288 regexp_arg = PG_GETARG_TEXT_P(1);
289 regexp = textndup (regexp_arg, VARSIZE (regexp_arg) - VARHDRSZ);
291 string_arg = PG_GETARG_TEXT_P(0);
292 string = textndup (string_arg, VARSIZE (string_arg) - VARHDRSZ);
294 if (g_regex_match_simple ((gchar *) regexp, (gchar *)
string, 0, 0))
301 PG_RETURN_BOOL (ret);
Datum sql_severity_matches_ov(PG_FUNCTION_ARGS)
Return max severity of level.
Datum sql_level_min_severity(PG_FUNCTION_ARGS)
Return min severity of level.
Datum sql_regexp(PG_FUNCTION_ARGS)
Return if argument 1 matches regular expression in argument 2.
Datum sql_valid_db_resource_type(PG_FUNCTION_ARGS)
Return max severity of level.
PG_FUNCTION_INFO_V1(sql_next_time)
double level_max_severity(const char *level, const char *class)
Get the minimum severity for a severity level and class.
int manage_count_hosts_max(const char *given_hosts, const char *exclude_hosts, int max_hosts)
Return number of hosts described by a hosts string.
Datum sql_next_time(PG_FUNCTION_ARGS)
Get the next time given schedule times.
double level_min_severity(const char *level, const char *class)
Get the minimum severity for a severity level and class.
Datum sql_level_max_severity(PG_FUNCTION_ARGS)
Return max severity of level.
Datum sql_max_hosts(PG_FUNCTION_ARGS)
Return number of hosts.
time_t next_time(time_t first, int period, int period_months, const char *timezone, int periods_offset)
Calculate the next time from now given a start time and a period.
int valid_db_resource_type(const char *)
Check whether a resource type table name is valid.