summaryrefslogtreecommitdiffstats
path: root/web/input/doc/faq/private-c-api.md
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2014-01-11 16:38:18 (GMT)
committerHolger Weiss <holger@zedat.fu-berlin.de>2014-01-11 16:38:18 (GMT)
commit7b0fa5d642466e7cdd0d326658c3c06c27f8a1ec (patch)
tree1bd1fe366d4063f29ed6930b0750c6bd7a72b7e9 /web/input/doc/faq/private-c-api.md
parent16bf58546355690e0d9cf4e7d181255aac73b5c6 (diff)
downloadsite-7b0fa5d642466e7cdd0d326658c3c06c27f8a1ec.tar.gz
Import most FAQ items from old web site
Import most of the FAQ entries from our old web site. A few outdated questions have been omitted, many of the imported ones were updated in one way or another, and the order of the development-related questions has been changed. Also, the phrasing of some questions has been modified (just to make the headings shorter). For the record, this is the original list of questions from the old web site: General ------- * Who controls the Nagios Plugins project? * What license is Nagios Plugins distributed under? * Who owns the copyright for the Nagios Plugin code? * Can I submit a patch to this project? * Do you accept donations? Compiling --------- * ./configure appears to hang * check_ldap, check_radius or check_pgsql don't compile even though configure output says the required libraries are present * How come check_http/check_tcp doesn't work with --ssl? * How do I compile the Nagios::Plugin perl module? * I can't compile check_mysql on solaris * I get '":types" is not exported by the Params::Validate module' when running tests * Why does Solaris use pst3 for check_procs? Installing ---------- * Some of the root plugins (check_dhcp and check_icmp) haven't been installed. What's happening? * Why aren't my plugins installed as the nagios user? And what about root plugins? Development ----------- * How do I use Git? * Can I add extra tests to the C routines? * Can I use the Nagios Plugins in my own project? * How can I find out more about writing a plugin? * How do I make changes on nagiosmib? * How do I prove the C routines work? * How do I use and update Gnulib? * How do I use the Nagios::Plugin perl module? * How do the test parameters in NPTest.pm work? * Private C APIs
Diffstat (limited to 'web/input/doc/faq/private-c-api.md')
-rw-r--r--web/input/doc/faq/private-c-api.md116
1 files changed, 116 insertions, 0 deletions
diff --git a/web/input/doc/faq/private-c-api.md b/web/input/doc/faq/private-c-api.md
new file mode 100644
index 0000000..585ca42
--- /dev/null
+++ b/web/input/doc/faq/private-c-api.md
@@ -0,0 +1,116 @@
1title: Private C APIs
2parent: FAQ
3---
4
5# Private C APIs
6
7This page describes the Nagios Plugins routines that can be accessed from the
8internal library.
9
10This page is in development, so these are not guaranteed to be available. As
11the API matures and is available in libraries, this information will be
12migrated to the [Development Guidelines][guidelines].
13
14## Basic Functions
15
16### np\_init(char \*plugin\_name, int argc, char \*\*argv)
17
18Initialize the Nagios Plugins routines. Pass the plugin name and `argc` and
19`argv` from `main()`.
20
21A variable `nagios_plugin` will be created for internal use.
22
23### np\_set\_args(int argc, char \*\*argv)
24
25Sets the internally held `argc` and `argv` values.
26
27Shouldn't really need this, but due to `np_extra_opts()`, this is set after
28that call.
29
30### np\_cleanup(void)
31
32Used to clean up allocated memory by the `nagios_plugin` variable. This is
33called by the `die()` routine before exiting.
34
35## State Information
36
37Saving and restoring state allows a plugin to know the last results and thus
38work out differences. This is especially useful when a plugin is capturing
39counter information, which increases with every request.
40
41This currently works by saving state information to a file, though the API
42doesn't care what the backend implementation is.
43
44*Note:* Binary data is not currently supported.
45
46Some things to be aware of, if you use state information:
47
48* There will be problems if a remote host is checked from two different Nagios
49 instances, as the state file on the remote host will be updated twice as
50 often.
51* Binary data may not restore on a program compiled with different options
52 from the program that saved it (e.g., 32 or 64 bit).
53* Binary data may include a structure containing a pointer. Pointer values
54 may not be used in the reading program - i.e., you need to overwrite the
55 value with something `malloc(3)`ed in the current run of the program.
56* State files could be left lying around. We recommend you run a regular job
57 to remove unmodified state files older than 1 week.
58
59### np\_enable\_state(char \*keyname, int data\_version)
60
61Enables the plugin state retention routines. Will set the filename for the
62state file to be `.../{keyname}`.
63
64The `keyname` will have any non alphanumerics replaced with "`_`".
65
66If `keyname` is `NULL`, will generate an SHA1 `keyname` based on the `argv` of
67the plugin (using the [extra-opts][extra-opts] parsed version, if applicable).
68
69*Note:* The `keyname` should be uniquely defined for a particular service, to
70avoid a second invocation of the plugin to use the state information from a
71different invocation. If in doubt, set `keyname=NULL` and allow the routine
72to calculate the `keyname`.
73
74### np\_state\_read(void)
75
76Reads the state file and returns a `state_data` variable.
77
78This routine will call `die()` with `UNKNOWN` if:
79
80* There was a problem reading the state file.
81
82Returns `NULL` if:
83
84* No state file exists - this is possible on the first run.
85* The state file format (internally held by the plugin) does not match.
86* The state data format (passed in `np_enable_state()`) does not match.
87
88Your plugin should always check for `NULL`. It is recommended that your
89plugin returns `OK` on `NULL` as this is similar to a "first run".
90
91If valid data was read, a pointer will be returned which points to a struct
92of:
93
94 typedef struct state_data_struct {
95 time_t time;
96 void *data;
97 int length; /* Of binary data. */
98 } state_data;
99
100### np\_state\_write\_string(time\_t data\_time, char \*string)
101
102If `data_time==0`, use current time. Creates state file, with state format
103version. Writes data version, time, and data. Creates a temporary file and
104then renames into place. There is a possible loss of data if two things
105writing to same key at same time, but there will not be a corrupted state
106file.
107
108### np\_state\_write\_binary(time\_t data\_time, char \*start, int length)
109
110Same as `np_state_write_string()`, but writes binary data. *Currently
111unimplemented.*
112
113[guidelines]: doc/guidelines.html "Nagios Plugin Development Guidelines"
114[extra-opts]: doc/extra-opts.html "Extra-Opts"
115
116<!--% # vim:set filetype=markdown textwidth=78 joinspaces: # %-->