oxidized 0.20.0 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +4 -0
  3. data/.github/PULL_REQUEST_TEMPLATE.md +12 -0
  4. data/.github/no-response.yml +13 -0
  5. data/.github/workflows/publishdocker.yml +13 -0
  6. data/.gitignore +4 -0
  7. data/.rubocop.yml +73 -0
  8. data/.rubocop_todo.yml +120 -0
  9. data/.travis.yml +6 -1
  10. data/CHANGELOG.md +693 -243
  11. data/Dockerfile +27 -19
  12. data/LICENSE +201 -0
  13. data/README.md +234 -913
  14. data/Rakefile +48 -7
  15. data/TODO.md +29 -23
  16. data/bin/console +1 -1
  17. data/bin/oxidized +6 -5
  18. data/docs/Configuration.md +313 -0
  19. data/docs/Creating-Models.md +140 -0
  20. data/docs/Hooks.md +274 -0
  21. data/docs/Model-Notes/AireOS.md +11 -0
  22. data/docs/Model-Notes/ArbOS.md +11 -0
  23. data/docs/Model-Notes/Comware.md +13 -0
  24. data/docs/Model-Notes/Cumulus.md +40 -0
  25. data/docs/Model-Notes/EOS.md +12 -0
  26. data/docs/Model-Notes/IOS.md +29 -0
  27. data/docs/Model-Notes/JunOS.md +33 -0
  28. data/docs/Model-Notes/LinuxGeneric.md +24 -0
  29. data/docs/Model-Notes/Netgear.md +87 -0
  30. data/docs/Model-Notes/Nokia.md +9 -0
  31. data/docs/Model-Notes/README.md +24 -0
  32. data/docs/Model-Notes/SmartAX-Huawei.md +35 -0
  33. data/docs/Model-Notes/VRP-Huawei.md +34 -0
  34. data/docs/Model-Notes/Viptela.md +12 -0
  35. data/docs/Model-Notes/XGS4600-Zyxel.md +36 -0
  36. data/docs/Outputs.md +190 -0
  37. data/docs/Ruby-API.md +199 -0
  38. data/docs/Sources.md +171 -0
  39. data/docs/Supported-OS-Types.md +227 -0
  40. data/docs/Troubleshooting.md +66 -0
  41. data/extra/nagios_check_failing_nodes.rb +9 -2
  42. data/extra/oxidized-report-git-commits +21 -40
  43. data/extra/oxidized-ubuntu.haproxy +45 -0
  44. data/extra/oxidized.logrotate +7 -0
  45. data/extra/oxidized.service +13 -0
  46. data/extra/rest_client.rb +7 -10
  47. data/extra/syslog.rb +47 -42
  48. data/lib/oxidized/cli.rb +41 -31
  49. data/lib/oxidized/config/vars.rb +9 -14
  50. data/lib/oxidized/config.rb +20 -13
  51. data/lib/oxidized/core.rb +8 -10
  52. data/lib/oxidized/hook/awssns.rb +6 -7
  53. data/lib/oxidized/hook/ciscosparkdiff.rb +43 -0
  54. data/lib/oxidized/hook/exec.rb +19 -24
  55. data/lib/oxidized/hook/githubrepo.rb +17 -17
  56. data/lib/oxidized/hook/noophook.rb +1 -1
  57. data/lib/oxidized/hook/slackdiff.rb +32 -19
  58. data/lib/oxidized/hook/xmppdiff.rb +59 -0
  59. data/lib/oxidized/hook.rb +63 -64
  60. data/lib/oxidized/input/cli.rb +22 -12
  61. data/lib/oxidized/input/exec.rb +28 -0
  62. data/lib/oxidized/input/ftp.rb +16 -15
  63. data/lib/oxidized/input/http.rb +72 -0
  64. data/lib/oxidized/input/input.rb +6 -6
  65. data/lib/oxidized/input/ssh.rb +64 -56
  66. data/lib/oxidized/input/telnet.rb +59 -102
  67. data/lib/oxidized/input/tftp.rb +9 -10
  68. data/lib/oxidized/jobs.rb +9 -10
  69. data/lib/oxidized/manager.rb +42 -44
  70. data/lib/oxidized/model/acos.rb +19 -20
  71. data/lib/oxidized/model/acsw.rb +62 -0
  72. data/lib/oxidized/model/adtran.rb +26 -0
  73. data/lib/oxidized/model/aen.rb +19 -0
  74. data/lib/oxidized/model/aireos.rb +9 -10
  75. data/lib/oxidized/model/airfiber.rb +22 -0
  76. data/lib/oxidized/model/alteonos.rb +58 -0
  77. data/lib/oxidized/model/alvarion.rb +0 -4
  78. data/lib/oxidized/model/aos.rb +11 -5
  79. data/lib/oxidized/model/aos7.rb +6 -7
  80. data/lib/oxidized/model/aosw.rb +30 -27
  81. data/lib/oxidized/model/apc_aos.rb +2 -5
  82. data/lib/oxidized/model/arbos.rb +26 -0
  83. data/lib/oxidized/model/aricentiss.rb +49 -0
  84. data/lib/oxidized/model/asa.rb +61 -22
  85. data/lib/oxidized/model/asyncos.rb +46 -0
  86. data/lib/oxidized/model/audiocodes.rb +28 -0
  87. data/lib/oxidized/model/audiocodesmp.rb +28 -0
  88. data/lib/oxidized/model/awplus.rb +84 -0
  89. data/lib/oxidized/model/axos.rb +16 -0
  90. data/lib/oxidized/model/boss.rb +77 -0
  91. data/lib/oxidized/model/br6910.rb +42 -45
  92. data/lib/oxidized/model/c4cmts.rb +6 -10
  93. data/lib/oxidized/model/cambium.rb +23 -0
  94. data/lib/oxidized/model/casa.rb +1 -1
  95. data/lib/oxidized/model/catos.rb +1 -3
  96. data/lib/oxidized/model/cisconga.rb +1 -3
  97. data/lib/oxidized/model/ciscosma.rb +42 -0
  98. data/lib/oxidized/model/ciscosmb.rb +30 -10
  99. data/lib/oxidized/model/ciscovpn3k.rb +11 -0
  100. data/lib/oxidized/model/cnos.rb +33 -0
  101. data/lib/oxidized/model/comnetms.rb +43 -0
  102. data/lib/oxidized/model/comtrol.rb +41 -0
  103. data/lib/oxidized/model/comware.rb +28 -16
  104. data/lib/oxidized/model/coriant8600.rb +3 -5
  105. data/lib/oxidized/model/coriantgroove.rb +26 -0
  106. data/lib/oxidized/model/corianttmos.rb +1 -3
  107. data/lib/oxidized/model/cumulus.rb +60 -49
  108. data/lib/oxidized/model/datacom.rb +1 -4
  109. data/lib/oxidized/model/dcnos.rb +46 -0
  110. data/lib/oxidized/model/dellx.rb +76 -0
  111. data/lib/oxidized/model/dlink.rb +5 -4
  112. data/lib/oxidized/model/dnos.rb +11 -5
  113. data/lib/oxidized/model/eciapollo.rb +34 -0
  114. data/lib/oxidized/model/edgecos.rb +49 -0
  115. data/lib/oxidized/model/edgeos.rb +12 -5
  116. data/lib/oxidized/model/edgeswitch.rb +2 -4
  117. data/lib/oxidized/model/enterasys.rb +28 -0
  118. data/lib/oxidized/model/eos.rb +8 -8
  119. data/lib/oxidized/model/fabricos.rb +4 -6
  120. data/lib/oxidized/model/fastiron.rb +66 -0
  121. data/lib/oxidized/model/fiberdriver.rb +2 -2
  122. data/lib/oxidized/model/firebrick.rb +31 -0
  123. data/lib/oxidized/model/firelinuxos.rb +41 -0
  124. data/lib/oxidized/model/firewareos.rb +3 -6
  125. data/lib/oxidized/model/fortios.rb +31 -19
  126. data/lib/oxidized/model/ftos.rb +8 -5
  127. data/lib/oxidized/model/fujitsupy.rb +5 -7
  128. data/lib/oxidized/model/gaiaos.rb +7 -11
  129. data/lib/oxidized/model/gcombnps.rb +84 -0
  130. data/lib/oxidized/model/grandstream.rb +9 -0
  131. data/lib/oxidized/model/hatteras.rb +9 -6
  132. data/lib/oxidized/model/hirschmann.rb +39 -0
  133. data/lib/oxidized/model/hpebladesystem.rb +20 -18
  134. data/lib/oxidized/model/hpemsa.rb +10 -0
  135. data/lib/oxidized/model/hpmsm.rb +84 -0
  136. data/lib/oxidized/model/ibos.rb +55 -0
  137. data/lib/oxidized/model/icotera.rb +27 -0
  138. data/lib/oxidized/model/ios.rb +63 -70
  139. data/lib/oxidized/model/iosxe.rb +5 -0
  140. data/lib/oxidized/model/iosxr.rb +2 -3
  141. data/lib/oxidized/model/ipos.rb +10 -6
  142. data/lib/oxidized/model/ironware.rb +20 -19
  143. data/lib/oxidized/model/isam.rb +5 -6
  144. data/lib/oxidized/model/junos.rb +9 -11
  145. data/lib/oxidized/model/linuxgeneric.rb +74 -0
  146. data/lib/oxidized/model/masteros.rb +3 -6
  147. data/lib/oxidized/model/mlnxos.rb +9 -10
  148. data/lib/oxidized/model/model.rb +72 -46
  149. data/lib/oxidized/model/mtrlrfs.rb +1 -4
  150. data/lib/oxidized/model/ndms.rb +23 -0
  151. data/lib/oxidized/model/netgear.rb +35 -15
  152. data/lib/oxidized/model/netonix.rb +2 -2
  153. data/lib/oxidized/model/netscaler.rb +6 -3
  154. data/lib/oxidized/model/nos.rb +5 -7
  155. data/lib/oxidized/model/nsxconfig.rb +22 -0
  156. data/lib/oxidized/model/nsxfirewall.rb +22 -0
  157. data/lib/oxidized/model/nxos.rb +13 -3
  158. data/lib/oxidized/model/oneos.rb +15 -9
  159. data/lib/oxidized/model/openbsd.rb +63 -0
  160. data/lib/oxidized/model/opengear.rb +3 -5
  161. data/lib/oxidized/model/openwrt.rb +78 -0
  162. data/lib/oxidized/model/opnsense.rb +19 -0
  163. data/lib/oxidized/model/os10.rb +46 -0
  164. data/lib/oxidized/model/outputs.rb +5 -7
  165. data/lib/oxidized/model/panos.rb +11 -12
  166. data/lib/oxidized/model/pfsense.rb +11 -6
  167. data/lib/oxidized/model/planet.rb +14 -17
  168. data/lib/oxidized/model/powerconnect.rb +24 -19
  169. data/lib/oxidized/model/procurve.rb +43 -11
  170. data/lib/oxidized/model/purityos.rb +12 -0
  171. data/lib/oxidized/model/qtech.rb +41 -0
  172. data/lib/oxidized/model/quantaos.rb +4 -6
  173. data/lib/oxidized/model/raisecom.rb +19 -0
  174. data/lib/oxidized/model/routeros.rb +26 -8
  175. data/lib/oxidized/model/saos.rb +1 -2
  176. data/lib/oxidized/model/screenos.rb +8 -11
  177. data/lib/oxidized/model/sgos.rb +45 -0
  178. data/lib/oxidized/model/siklu.rb +1 -3
  179. data/lib/oxidized/model/slxos.rb +59 -0
  180. data/lib/oxidized/model/smartax.rb +25 -0
  181. data/lib/oxidized/model/sonicos.rb +51 -0
  182. data/lib/oxidized/model/speedtouch.rb +34 -0
  183. data/lib/oxidized/model/sros.rb +96 -0
  184. data/lib/oxidized/model/stoneos.rb +32 -0
  185. data/lib/oxidized/model/supermicro.rb +6 -41
  186. data/lib/oxidized/model/tdre.rb +30 -0
  187. data/lib/oxidized/model/telco.rb +24 -0
  188. data/lib/oxidized/model/timos.rb +6 -114
  189. data/lib/oxidized/model/tmos.rb +6 -3
  190. data/lib/oxidized/model/tplink.rb +11 -11
  191. data/lib/oxidized/model/trango.rb +21 -42
  192. data/lib/oxidized/model/ucs.rb +30 -0
  193. data/lib/oxidized/model/viptela.rb +29 -0
  194. data/lib/oxidized/model/voltaire.rb +9 -12
  195. data/lib/oxidized/model/voss.rb +17 -6
  196. data/lib/oxidized/model/vrp.rb +11 -6
  197. data/lib/oxidized/model/vyatta.rb +8 -6
  198. data/lib/oxidized/model/weos.rb +20 -0
  199. data/lib/oxidized/model/xos.rb +20 -8
  200. data/lib/oxidized/model/zhoneolt.rb +2 -2
  201. data/lib/oxidized/model/zynos.rb +1 -3
  202. data/lib/oxidized/model/zynoscli.rb +36 -0
  203. data/lib/oxidized/model/zynosgs.rb +38 -0
  204. data/lib/oxidized/node/stats.rb +33 -8
  205. data/lib/oxidized/node.rb +86 -95
  206. data/lib/oxidized/nodes.rb +48 -44
  207. data/lib/oxidized/output/file.rb +32 -37
  208. data/lib/oxidized/output/git.rb +138 -153
  209. data/lib/oxidized/output/gitcrypt.rb +228 -242
  210. data/lib/oxidized/output/http.rb +35 -34
  211. data/lib/oxidized/output/output.rb +2 -3
  212. data/lib/oxidized/source/csv.rb +50 -44
  213. data/lib/oxidized/source/http.rb +58 -58
  214. data/lib/oxidized/source/source.rb +9 -10
  215. data/lib/oxidized/source/sql.rb +47 -45
  216. data/lib/oxidized/string.rb +18 -14
  217. data/lib/oxidized/version.rb +17 -1
  218. data/lib/oxidized/worker.rb +72 -33
  219. data/oxidized.gemspec +20 -19
  220. metadata +180 -36
  221. data/.ruby-version +0 -1
  222. data/Gemfile.lock +0 -44
@@ -0,0 +1,36 @@
1
+ # ZynOS Configuration
2
+
3
+ ## FTP
4
+
5
+ FTP access is only possible as admin, other users can login but cannot pull the files.
6
+ For the XGS4600 series the config file is _config_ and not _config-0_
7
+
8
+ The following line in _oxidized/lib/oxidized/model/zynos.rb_ will need changing
9
+
10
+ ```text
11
+ cmd 'config-0'
12
+ ```
13
+
14
+ The inclusion of an extra ftp option is also require. Within _input_ add the following
15
+
16
+ ```yaml
17
+ input:
18
+ ftp:
19
+ passive: false
20
+ ```
21
+
22
+ ## SSH/TelNet
23
+
24
+ Below is the table from the XGS4600 CLI Reference Guide (Version 3.79~4.50 Edition 1, 07/2017)
25
+ Take this table with a pinch of salt, level 3 will not allow _show running-config_!
26
+
27
+ Privilege Level | Types of commands at this privilege level
28
+ ----------------|-------------------------------------------
29
+ 0|Display basic system information.
30
+ 3|Display configuration or status.
31
+ 13|Configure features except for login accounts, SNMP user accounts, the authentication method sequence and authorization settings, multiple logins, administrator and enable passwords, and configuration information display.
32
+ 14|Configure login accounts, SNMP user accounts, the authentication method sequence and authorization settings, multiple logins, and administrator and enable passwords, and display configuration information.
33
+
34
+ Oxidized can now retrieve your configuration!
35
+
36
+ Back to [Model-Notes](README.md)
data/docs/Outputs.md ADDED
@@ -0,0 +1,190 @@
1
+ # Outputs
2
+
3
+ ## Output: File
4
+
5
+ Parent directory needs to be created manually, one file per device, with most recent running config.
6
+
7
+ ```yaml
8
+ output:
9
+ file:
10
+ directory: /var/lib/oxidized/configs
11
+ ```
12
+
13
+ ## Output: Git
14
+
15
+ This uses the rugged/libgit2 interface. So you should remember that normal Git hooks will not be executed.
16
+
17
+ For a single repository containing all devices:
18
+
19
+ ```yaml
20
+ output:
21
+ default: git
22
+ git:
23
+ user: Oxidized
24
+ email: o@example.com
25
+ repo: "/var/lib/oxidized/devices.git"
26
+ ```
27
+
28
+ And for group-based repositories:
29
+
30
+ ```yaml
31
+ output:
32
+ default: git
33
+ git:
34
+ user: Oxidized
35
+ email: o@example.com
36
+ repo: "/var/lib/oxidized/git-repos/default.git"
37
+ ```
38
+
39
+ Oxidized will create a repository for each group in the same directory as the `default.git`. For
40
+ example:
41
+
42
+ ```csv
43
+ host1:ios:first
44
+ host2:nxos:second
45
+ ```
46
+
47
+ This will generate the following repositories:
48
+
49
+ ```bash
50
+ $ ls /var/lib/oxidized/git-repos
51
+
52
+ default.git first.git second.git
53
+ ```
54
+
55
+ If you would like to use groups and a single repository, you can force this with the `single_repo` config.
56
+
57
+ ```yaml
58
+ output:
59
+ default: git
60
+ git:
61
+ single_repo: true
62
+ repo: "/var/lib/oxidized/devices.git"
63
+
64
+ ```
65
+
66
+ ## Output: Git-Crypt
67
+
68
+ This uses the gem git and system git-crypt interfaces. Have a look at [GIT-Crypt](https://www.agwa.name/projects/git-crypt/) documentation to know how to install it.
69
+ Additionally to user and email informations, you have to provide the users ID that can be a key ID, a full fingerprint, an email address, or anything else that uniquely identifies a public key to GPG (see "HOW TO SPECIFY A USER ID" in the gpg man page).
70
+
71
+ For a single repository containing all devices:
72
+
73
+ ```yaml
74
+ output:
75
+ default: gitcrypt
76
+ gitcrypt:
77
+ user: Oxidized
78
+ email: o@example.com
79
+ repo: "/var/lib/oxidized/devices"
80
+ users:
81
+ - "0x0123456789ABCDEF"
82
+ - "<user@example.com>"
83
+ ```
84
+
85
+ And for group-based repositories:
86
+
87
+ ```yaml
88
+ output:
89
+ default: gitcrypt
90
+ gitcrypt:
91
+ user: Oxidized
92
+ email: o@example.com
93
+ repo: "/var/lib/oxidized/git-repos/default"
94
+ users:
95
+ - "0xABCDEF0123456789"
96
+ - "0x0123456789ABCDEF"
97
+ ```
98
+
99
+ Oxidized will create a repository for each group in the same directory as the `default`. For
100
+ example:
101
+
102
+ ```csv
103
+ host1:ios:first
104
+ host2:nxos:second
105
+ ```
106
+
107
+ This will generate the following repositories:
108
+
109
+ ```bash
110
+ $ ls /var/lib/oxidized/git-repos
111
+
112
+ default.git first.git second.git
113
+ ```
114
+
115
+ If you would like to use groups and a single repository, you can force this with the `single_repo` config.
116
+
117
+ ```yaml
118
+ output:
119
+ default: gitcrypt
120
+ gitcrypt:
121
+ single_repo: true
122
+ repo: "/var/lib/oxidized/devices"
123
+ users:
124
+ - "0xABCDEF0123456789"
125
+ - "0x0123456789ABCDEF"
126
+
127
+ ```
128
+
129
+ Please note that user list is only updated once at creation.
130
+
131
+ ## Output: Http
132
+
133
+ The HTTP output will POST a config to the specified HTTP URL. Basic username/password authentication is supported.
134
+
135
+ Example HTTP output configuration:
136
+
137
+ ```yaml
138
+ output:
139
+ default: http
140
+ http:
141
+ user: admin
142
+ password: changeit
143
+ url: "http://192.168.162.50:8080/db/coll"
144
+ ```
145
+
146
+ ## Output types
147
+
148
+ If you prefer to have different outputs in different files and/or directories, you can easily do this by modifying the corresponding model. To change the behaviour for IOS, you would edit `lib/oxidized/model/ios.rb` (run `gem contents oxidized` to find out the full file path).
149
+
150
+ For example, let's say you want to split out `show version` and `show inventory` into separate files in a directory called `nodiff` which your tools will not send automated diffstats for. You can apply a patch along the lines of
151
+
152
+ ```text
153
+ - cmd 'show version' do |cfg|
154
+ - comment cfg.lines.first
155
+ + cmd 'show version' do |state|
156
+ + state.type = 'nodiff'
157
+ + state
158
+
159
+ - cmd 'show inventory' do |cfg|
160
+ - comment cfg
161
+ + cmd 'show inventory' do |state|
162
+ + state.type = 'nodiff'
163
+ + state
164
+ + end
165
+
166
+ - cmd 'show running-config' do |cfg|
167
+ - cfg = cfg.each_line.to_a[3..-1].join
168
+ - cfg.gsub! /^Current configuration : [^\n]*\n/, ''
169
+ - cfg.sub! /^(ntp clock-period).*/, '! \1'
170
+ - cfg.gsub! /^\ tunnel\ mpls\ traffic-eng\ bandwidth[^\n]*\n*(
171
+ + cmd 'show running-config' do |state|
172
+ + state = state.each_line.to_a[3..-1].join
173
+ + state.gsub! /^Current configuration : [^\n]*\n/, ''
174
+ + state.sub! /^(ntp clock-period).*/, '! \1'
175
+ + state.gsub! /^\ tunnel\ mpls\ traffic-eng\ bandwidth[^\n]*\n*(
176
+ (?:\ [^\n]*\n*)*
177
+ tunnel\ mpls\ traffic-eng\ auto-bw)/mx, '\1'
178
+ - cfg
179
+ + state = Oxidized::String.new state
180
+ + state.type = 'nodiff'
181
+ + state
182
+ ```
183
+
184
+ which will result in the following layout
185
+
186
+ ```text
187
+ diff/$FQDN--show_running_config
188
+ nodiff/$FQDN--show_version
189
+ nodiff/$FQDN--show_inventory
190
+ ```
data/docs/Ruby-API.md ADDED
@@ -0,0 +1,199 @@
1
+ # Ruby API
2
+
3
+ The following objects exist in Oxidized.
4
+
5
+ ## Input
6
+
7
+ * gets config from nodes
8
+ * must implement 'connect', 'get', 'cmd'
9
+ * 'ssh', 'telnet', 'ftp', 'tftp', 'http' implemented
10
+
11
+ #### http
12
+ * Communicates with a device over http/https
13
+ * Configurable variables from within model @username, @password, @headers.
14
+ * @username,@password are used in a Basic Authentication method.
15
+ * @headers is a Hash of key value pairs of headers to pass along with the request.
16
+ * Within the sources config under input you define a YAML stanza like the below, this will tell Oxidized to validate certificates on the request
17
+ ```yaml
18
+ input:
19
+ http:
20
+ ssl_verify: true
21
+ ```
22
+
23
+ ## Output
24
+
25
+ * stores config
26
+ * must implement 'store' (may implement 'fetch')
27
+ * 'git' and 'file' (store as flat ascii) implemented
28
+
29
+ ## Source
30
+
31
+ * gets list of nodes to poll
32
+ * must implement 'load'
33
+ * source can have 'name', 'model', 'group', 'username', 'password', 'input', 'output', 'prompt' for each device.
34
+ * `name` - name of the device
35
+ * `model` - model to use ('ios', 'junos', etc).The model is loaded dynamically by the first node of that model type. (Also default in config file)
36
+ * `input` - method to acquire config, loaded dynamically as needed (Also default in config file)
37
+ * `output` - method to store config, loaded dynamically as needed (Also default in config file)
38
+ * `prompt` - prompt used for node (Also default in config file, can be specified in model too)
39
+ * 'sql', 'csv' and 'http' (supports any format with single entry per line, like router.db)
40
+
41
+ ## Model
42
+
43
+ ### At the top level
44
+
45
+ A model may use several methods at the top level in the class. `cfg` is
46
+ executed in input/output/source context. `cmd` is executed within an instance
47
+ of the model.
48
+
49
+ #### `cfg`
50
+
51
+ `cfg` may be called with a list of methods (`:ssh`, `:telnet`) and a block with
52
+ zero parameters. Calling `cfg` registers the given access methods and calling
53
+ it at least once is required for a model to work.
54
+
55
+ The block may contain commands to change some behaviour for the given methods
56
+ (e.g. calling `post_login` to disable the pager).
57
+
58
+ Supports [monkey patching](#monkey-patching).
59
+
60
+ #### `cmd`
61
+
62
+ Is used to specify commands that should be executed on a model in order to
63
+ gather its configuration. It can be called with:
64
+
65
+ * Just a string
66
+ * A string and a block
67
+ * `:all` and a block
68
+ * `:secret` and a block
69
+
70
+ The block takes a single parameter `cfg` containing the output of the command
71
+ being processed.
72
+
73
+ Calling `cmd` with just a string will emit the output of the command given in
74
+ that string as configuration.
75
+
76
+ Calling `cmd` with a string and a block will pass the output of the given
77
+ command to the block, then emit its return value (that must be a string) as
78
+ configuration.
79
+
80
+ Calling `cmd` with `:all` and a block will pass all command output through this
81
+ block before emitting it. This is useful if some cleanup is required of the
82
+ output of all commands.
83
+
84
+ Calling `cmd` with `:secret` and a block will pass all configuration to the
85
+ given block before emitting it to hide secrets if secret hiding is enabled. The
86
+ block should replace any secrets with `'<hidden>'` and return the resulting
87
+ string.
88
+
89
+ Execution order is `:all`, `:secret`, and lastly the command specific block, if
90
+ given.
91
+
92
+ Supports [monkey patching](#monkey-patching).
93
+
94
+ #### `comment`
95
+
96
+ Called with a single string containing the string to prepend for comments in
97
+ emitted configuration for this model.
98
+
99
+ If not specified the default of `'# '` will be used (note the trailing space).
100
+
101
+ #### `prompt`
102
+
103
+ Is called with a regular expression that is used to detect when command output
104
+ ends after a command has been executed.
105
+
106
+ If not specified, a default of `/^([\w.@-]+[#>]\s?)$/` is used.
107
+
108
+ #### `expect`
109
+
110
+ Called with a regular expression and a block. The block takes two parameters:
111
+ the regular expression, and the data containing the match.
112
+
113
+ The passed data is replaced by the return value of the block.
114
+
115
+ `expect` can be used to, for example, strip escape sequences from output before
116
+ it's further processed.
117
+
118
+ Supports [monkey patching](#monkey-patching).
119
+
120
+ ### At the second level
121
+
122
+ The following methods are available:
123
+
124
+ #### `comment`
125
+
126
+ Used inside `cmd` invocations. Comments out every line in the passed string and
127
+ returns the result.
128
+
129
+ #### `password`
130
+
131
+ Used inside `cfg` invocations to specify the regular expression used to detect
132
+ the password prompt. If not specified, the default of `/^Password/` is used.
133
+
134
+ #### `post_login`
135
+
136
+ Used inside `cfg` invocations to specify commands to run once Oxidized has
137
+ logged in to the device. Takes one argument that is either a block (taking zero
138
+ parameters) or a string containing a command to execute.
139
+
140
+ This allows `post_login` to be used for any model-specific items prior to
141
+ running the regular commands. This could include disabling the output pager
142
+ or timestamp outputs that would cause constant differences.
143
+
144
+ Supports [monkey patching](#monkey-patching).
145
+
146
+ #### `pre_logout`
147
+
148
+ Used to specify commands to run before Oxidized closes the connection to the
149
+ device. Takes one argument that is either a block (taking zero parameters) or a
150
+ string containing a command to execute.
151
+
152
+ This allows `pre_logout` to be used to 'undo' any changes that may have been
153
+ needed via `post_login` (restore pager output, etc.)
154
+
155
+ Supports [monkey patching](#monkey-patching).
156
+
157
+ #### `send`
158
+
159
+ Usually used inside `expect` or blocks passed to `post_login`/`pre_logout`.
160
+ Takes a single parameter: a string to be sent to the device.
161
+
162
+ ### Monkey patching
163
+
164
+ Several model blocks accept behavior-modifying arguments that make monkey
165
+ patching existing blocks easier. This is primarily useful when a user-supplied
166
+ model aims to override or extend existing behavior of a model included in Oxidized.
167
+
168
+ This functionality is supported by `cfg`, `cmd`, `pre_*`, `post_*`, and `expect`
169
+ blocks.
170
+
171
+ #### `clear: true`
172
+
173
+ Resets the existing block, allowing the user to completely override its contents.
174
+
175
+ #### `prepend: true`
176
+
177
+ Ensures that the contents of the block are prepended, rather than appended (the
178
+ default) to an existing block.
179
+
180
+ ### `String` convenience methods
181
+
182
+ Since configuration processing tasks are occasionally similar across models,
183
+ Oxidized provides an extended [`String`](/lib/oxidized/string.rb) class with the
184
+ intention of providing convenience methods and eliminating code duplication.
185
+
186
+ #### `cut_tail`
187
+
188
+ Returns a multi-line string without the last line, or an empty string if only a
189
+ single line was present.
190
+
191
+ #### `cut_head`
192
+
193
+ Returns a multi-line string without the first line, or an empty string if only a
194
+ single line was present.
195
+
196
+ #### `cut_both`
197
+
198
+ Returns a multi-line string without the first and last lines, or an empty string
199
+ if fewer than three lines were present.
data/docs/Sources.md ADDED
@@ -0,0 +1,171 @@
1
+ # Sources
2
+
3
+ ## Source: CSV
4
+
5
+ One line per device, colon separated. If `ip` isn't present, a DNS lookup will be done against `name`. For large installations, setting `ip` will dramatically reduce startup time.
6
+
7
+ ```yaml
8
+ source:
9
+ default: csv
10
+ csv:
11
+ file: /var/lib/oxidized/router.db
12
+ delimiter: !ruby/regexp /:/
13
+ map:
14
+ name: 0
15
+ ip: 1
16
+ model: 2
17
+ username: 3
18
+ password: 4
19
+ vars_map:
20
+ enable: 5
21
+ ```
22
+
23
+ Example csv `/var/lib/oxidized/router.db`:
24
+
25
+ ```text
26
+ rtr01.local:192.168.1.1:ios:oxidized:5uP3R53cR3T:T0p53cR3t
27
+ ```
28
+
29
+ If you would like to use a GPG encrypted file as the source then you can use the following example:
30
+
31
+ ```yaml
32
+ source:
33
+ default: csv
34
+ csv:
35
+ file: ~/.config/oxidized/router.db
36
+ delimiter: !ruby/regexp /:/
37
+ gpg: true
38
+ gpg_password: 'password'
39
+ map:
40
+ name: 0
41
+ model: 1
42
+ ```
43
+
44
+ Please note, if you are running GPG v2 then you will be prompted for your gpg password on start up, if you use GPG >= 2.1 then you can add the following config to stop that behaviour:
45
+
46
+ Within `~/.gnupg/gpg-agent.conf`
47
+
48
+ ```text
49
+ allow-loopback-pinentry
50
+ ```
51
+
52
+ and within: `~/.gnupg/gpg.conf`
53
+
54
+ ```text
55
+ pinentry-mode loopback
56
+ ```
57
+
58
+ ## Source: SQL
59
+
60
+ Oxidized uses the `sequel` ruby gem. You can use a variety of databases that aren't explicitly listed. For more information visit https://github.com/jeremyevans/sequel Make sure you have the correct adapter!
61
+
62
+ **NOTE** - Many database engines have reserved keywords that may conflict with Oxidized configuration field names (such as 'name', 'group', etc). Pay attention to any names that are used and observed proper quoting methods to avoid errors or unpredictable results.
63
+
64
+ ## Source: MYSQL
65
+
66
+ `sudo apt-get install libmysqlclient-dev`
67
+
68
+ The values correspond to your fields in the DB such that ip, model, etc are field names in the DB
69
+
70
+ ```yaml
71
+ source:
72
+ default: sql
73
+ sql:
74
+ adapter: mysql2
75
+ database: oxidized
76
+ table: nodes
77
+ user: root
78
+ password: rootpass
79
+ map:
80
+ name: ip
81
+ model: model
82
+ username: username
83
+ password: password
84
+ vars_map:
85
+ enable: enable
86
+ ```
87
+
88
+ ## Source: SQLite
89
+
90
+ One row per device, filtered by hostname.
91
+
92
+ ```yaml
93
+ source:
94
+ default: sql
95
+ sql:
96
+ adapter: sqlite
97
+ database: "/var/lib/oxidized/nodes.db"
98
+ table: nodes
99
+ map:
100
+ name: fqdn
101
+ model: model
102
+ username: username
103
+ password: password
104
+ vars_map:
105
+ enable: enable
106
+ ```
107
+
108
+ ## Custom SQL Query Support
109
+
110
+ You may also implement a custom SQL query to retrieve the nodelist using SQL syntax with the `query:` configuration parameter under the `sql:` stanza.
111
+
112
+ ### Custom SQL Query Examples
113
+
114
+ You may have a table named `nodes` which contains a boolean to indicate if the nodes should be enabled (fetched via oxidized). This can be used in the custom SQL query to avoid fetching from known impacted nodes.
115
+
116
+ In your configuration, you would add the `query:` parameter and specify the SQL query. Make sure to put this within the `sql:` configuration section.
117
+
118
+ ```sql
119
+ query: "SELECT * FROM nodes WHERE enabled = True"
120
+ ```
121
+
122
+ Since this is an SQL query, you can also provide a more advanced query to assist in more complicated oxidized deployments. The exact deployment is up to you on how you design your database and oxidized fetchers.
123
+
124
+ In this example we limit the nodes to two "POPs" of `mypop1` and `mypop2`. We also require the nodes to have the `enabled` boolean set to `True`.
125
+
126
+ ```sql
127
+ query: "SELECT * FROM nodes WHERE pop IN ('mypop1','mypop2') AND enabled = True"
128
+ ```
129
+
130
+ The order of the nodes returned will influence the order that nodes are fetched by oxidized. You can use standard SQL `ORDER BY` clauses to influence the node order.
131
+
132
+ You should always test your SQL query before using it in the oxidized configuration as there is no syntax or error checking performed before sending it to the database engine.
133
+
134
+ Consult your database documentation for more information on query language and table optimization.
135
+
136
+ ## Source: HTTP
137
+
138
+ One object per device.
139
+
140
+ HTTP Supports basic auth, configure the user and pass you want to use under the http: section.
141
+
142
+ ```yaml
143
+ source:
144
+ default: http
145
+ http:
146
+ url: https://url/api
147
+ scheme: https
148
+ delimiter: !ruby/regexp /:/
149
+ user: username
150
+ pass: password
151
+ map:
152
+ name: hostname
153
+ model: os
154
+ username: username
155
+ password: password
156
+ vars_map:
157
+ enable: enable
158
+ headers:
159
+ X-Auth-Token: 'somerandomstring'
160
+ ```
161
+
162
+ You can also pass `secure: false` if you want to disable ssl certificate verification:
163
+
164
+ ```yaml
165
+ source:
166
+ default: http
167
+ http:
168
+ url: https://url/api
169
+ scheme: https
170
+ secure: false
171
+ ```