File: pynag-command.rst

package info (click to toggle)
pynag 1.1.2+dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,324 kB
  • sloc: python: 9,792; makefile: 200
file content (167 lines) | stat: -rw-r--r-- 4,887 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167

====
NAME
====

SYNOPSIS
--------
pynag <sub-command> [options] [arguments]

DESCRIPTION
-----------
pynag is a command-line utility that can be used to view or change current
nagios configuration.

sub-commands
------------

*list*
   
   print to screen nagios configuration objects as specified by a WHERE
   clause
   
      | pynag list [attribute1] [attribute2] [WHERE ...]

*update*
   
   modify specific attributes of nagios objects as specified by a WHERE
   and SET clause
    
      | pynag update set attr1=value WHERE attr=value and attr=value

*delete*
   
   Delete objects from nagios configuration as specified by a WHERE clause

      | pynag delete delete <WHERE ...>

*add*

   Add a new object definition

      | pynag add <object_type> <attr1=value1> [attr2=value2]

*copy*

   Copy objects, specifiying which attributes to change

      | pynag copy <WHERE ...> <SET attr1=value1 [attr2=value2] ...>

*execute*

   Executes the currently configured check command for a host or a service

      | pynag execute <host_name> [service_description]

*config*

   modify values in main nagios configuration file (nagios.cfg)

      | pynag config [--set <attribute=value>] [--old_value=attribute]
      | pynag config [--append <attribute=value>] [--old_value=attribute]
      | pynag config [--remove <attribute>] [--old_value=attribute]
      | pynag config [--get <attribute>]

WHERE statements
----------------
Some Subcommands use WHERE statements to filter which objects to work
with.  Where has certain similarity with SQL syntax.

Syntax:
   | WHERE <attr=value> [AND attr=value] [OR attr=value] \
   |   [another where statement]

   where "attr" is any nagios attribute (i.e. host_name or 
   service_description).

Example:
   | pynag list WHERE host_name=localhost and object_type=service
   | pynag list WHERE object_type=host or object_type=service

Any search attributes have the same syntax as the pynag filter. For example
these work just fine:

   | pynag list WHERE host_name__contains=production
   | pynag list WHERE host_name__startswith=prod
   | pynag list WHERE host_name__notcontains=test
   | pynag list host_name address WHERE address__exists=True
   | pynag list host_name WHERE register__isnot=0

If you specificly want to match against non existent attribute,
use attribute__exists=True or attribute=None.

The pynag filter supports few parameters that are not just attributes.

Example:

* filename                 -- The filename which the object belongs
* id                       -- pynag unique identifier for the object
* effective_command_line   -- command which nagios will execute

Of course these can be combined with the pynag filter syntax:

   | pynag list where filename__startswith=/etc/nagios/conf.d/
   | pynag list host_name service_description effective_command_line

For detailed description of the filter see pydoc for
pynag.Model.ObjectDefinition.filter()

SET statements
--------------
Subcommands that use SET statements (like update or copy) use them a list of
attributes change for a specific object.

Syntax:
   | SET <attr1=value1> [attr2=value2] [...]

Example:
   | pynag update SET address=127.0.0.1 WHERE host_name=localhost and object_type=host

EXAMPLES
--------
List all services that have "myhost" as a host_name
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| pynag list host_name service_description WHERE host_name=myhost and object_type=service

Set check_period to 24x7 on all services that belong to host "myhost"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| pynag update set check_period=24x7 WHERE host_name=myhost

list examples
^^^^^^^^^^^^^
| pynag list host_name address WHERE object_type=host
| pynag list host_name service_description WHERE host_name=examplehost and object_type=service


update examples
^^^^^^^^^^^^^^^
| pynag update SET host_name=newhostname WHERE host_name=oldhostname
| pynag update SET address=127.0.0.1 WHERE host_name='examplehost.example.com' and object_type=host
| pynag update UNSET contacts WHERE host_name='examplehost.example.com' and object_type=host

copy examples
^^^^^^^^^^^^^
| pynag copy SET host_name=newhostname WHERE  host_name=oldhostname
| pynag copy SET address=127.0.0.1 WHERE host_name='examplehost.example.com' and object_type=host

add examples
^^^^^^^^^^^^
| pynag add host host_name=examplehost use=generic-host address=127.0.0.1
| pynag add service service_description="Test Service" use="check_nrpe" host_name="localhost"

delete examples
^^^^^^^^^^^^^^^
| pynag delete where object_type=service and host_name='mydeprecated_host'
| pynag delete where filename__startswith='/etc/nagios/myoldhosts'

execute examples
^^^^^^^^^^^^^^^^
| pynag execute localhost
| pynag execute localhost "Disk Space


Additional Resources
--------------------
See http://github.com/pynag/pynag.git for more information.