Skip to content

Commit 83c476f

Browse files
Merge pull request #22 from netboxlabs/features-1.1.0
Features 1.1.0
2 parents 1c39a82 + 8f8980f commit 83c476f

15 files changed

+1152
-3
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,6 @@ inventory
173173
tests/
174174

175175
app_config.yml
176-
176+
netbox_setup_custom_fields.yml
177+
netbox_importer.py*
178+
netbox_setup_objects.yml
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
proxmox_api_config:
2+
api_host: proxmox-ip-or-hostname
3+
api_port: 8006
4+
api_user: proxmox_api_user
5+
api_token_id: name_of_proxmox_api_token
6+
api_token_secret: proxmox_api_secret_token
7+
verify_ssl: false
8+
netbox_api_config:
9+
api_proto: http # or https
10+
api_host: name or ip of NetBox host
11+
api_port: 8000
12+
api_token: netbox_api_secret_token
13+
verify_ssl: false # or true, up to you
14+
proxmox:
15+
cluster_name: proxmox-ve
16+
netbox:
17+
cluster_role: Proxmox
18+
vm_role: "Proxmox VM"
19+
automation_type: choices are ansible_automation or flask_application
20+
ansible_automation:
21+
host: name or ip of AWX/Tower/AAP host
22+
http_proto: http or https
23+
http_port: 80 or whatever
24+
ssl_verify: false # or true
25+
username: awx_user # should have permissions to view both projects and templates
26+
password: awx_password
27+
project_name: netbox-proxmox-ee-test1 # or whatever you named your project
28+
flask_application:
29+
host: name or ip of where Flask application is running
30+
http_proto: http or https
31+
http_port: 9000 or whatever
32+
ssl_verify: false # or true
33+
netbox_webhook_name: "netbox-proxmox-webhook"

docs/netbox-customization.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,56 @@ In the NetBox UI, you will need to create the following custom field choices
1010
2. `proxmox-vm-templates` will be used to correlate a Proxmox VM template with the Proxmox VM that you will provision
1111
3. `proxmox-vm-storage` will be used to correlate an underlying Proxmox VM storage volume with the Proxmox VM you will provision
1212

13-
In the NetBox UI, navigate to Customization > Custom Field Choices
13+
#### Automated NetBox Objects and Custom Fields Creation
1414

15+
If you'd prefer to manually create the webhook and event rules in NetBox, you can skip to the next section. Otherwise, proceed with the following to automate the creation of the webhook and event rules in NetBox.
16+
17+
`netbox-proxmox-automation` version 1.1.0 and newer ships with a convenience script, `netbox_setup_objects_and_custom_fields.py`, that when used alongside a configuration file of your choice, will greatly simplify this process. In the case of AWX/Tower/AAP, `netbox_setup_objects_and_custom_fields.py` will query your AWX/Tower/AAP instance for project and template(s) information; this information will then be used to create the corresponding webhooks and event rules in NetBox.
18+
19+
There exists a sample configuration file called `netbox_setup_objects.yml-sample` under the conf.d directory of this git repository. Copy this file to a location of your choice, and season it to taste. In the end you should have a configuration that looks something like this.
20+
21+
```
22+
proxmox_api_config:
23+
api_host: proxmox-ip-or-hostname
24+
api_port: 8006
25+
api_user: proxmox_api_user
26+
api_token_id: name_of_proxmox_api_token
27+
api_token_secret: proxmox_api_secret_token
28+
verify_ssl: false
29+
netbox_api_config:
30+
api_proto: http # or https
31+
api_host: name or ip of NetBox host
32+
api_port: 8000
33+
api_token: netbox_api_secret_token
34+
verify_ssl: false # or true, up to you
35+
proxmox:
36+
cluster_name: proxmox-ve
37+
netbox:
38+
cluster_role: Proxmox
39+
vm_role: "Proxmox VM"
40+
```
41+
42+
Usage:
43+
44+
```
45+
shell$ cd setup
46+
47+
shell$ pwd
48+
/some/path/netbox-proxmox-automation/setup
49+
50+
shell$ python3 -m venv venv
51+
52+
shell$ source venv/bin/activate
53+
54+
(venv) shell$ pip install -r requirements.txt
55+
56+
(venv) shell$ ./netbox_setup_objects_and_custom_fields.py --config /path/to/your/configuration.yml
57+
```
58+
59+
Then verify that everything has been created. You can skip the rest of this document if so.
60+
61+
62+
If *not* using automation, in the NetBox UI, navigate to Customization > Custom Field Choices
1563

1664
#### proxmox-node
1765

docs/netbox-event-rules-and-webhooks-awx-aap.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,63 @@ Regardless of whether you are using a Flask (or other) application for Proxmox a
2424

2525
As noted earlier, AWX/Tower/AAP will perform Proxmox automation through separate (job) templates. This section walks you through how (NetBox) webhooks and (NetBox) event rules are handled by AWX.
2626

27+
#### Automated Webhook and Event Rules Configuration
28+
29+
If you'd prefer to manually create the webhook and event rules in NetBox, you can skip to the next section. Otherwise, proceed with the following to automate the creation of the webhook and event rules in NetBox.
30+
31+
`netbox-proxmox-automation` version 1.1.0 and newer ships with a convenience script, `netbox_setup_webhook_and_event_rules.py`, that when used alongside a configuration file of your choice, will greatly simplify this process. In the case of AWX/Tower/AAP, `netbox_setup_webhook_and_event_rules.py` will query your AWX/Tower/AAP instance for project and template(s) information; this information will then be used to create the corresponding webhooks and event rules in NetBox.
32+
33+
There exists a sample configuration file called `netbox_setup_objects.yml-sample` under the conf.d directory of this git repository. Copy this file to a location of your choice, and season it to taste. In the end you should have a configuration that looks something like this.
34+
35+
```
36+
proxmox_api_config:
37+
api_host: proxmox-ip-or-hostname
38+
api_port: 8006
39+
api_user: proxmox_api_user
40+
api_token_id: name_of_proxmox_api_token
41+
api_token_secret: proxmox_api_secret_token
42+
verify_ssl: false
43+
netbox_api_config:
44+
api_proto: http # or https
45+
api_host: name or ip of NetBox host
46+
api_port: 8000
47+
api_token: netbox_api_secret_token
48+
verify_ssl: false # or true, up to you
49+
proxmox:
50+
cluster_name: proxmox-ve
51+
netbox:
52+
cluster_role: Proxmox
53+
vm_role: "Proxmox VM"
54+
automation_type: ansible_automation
55+
ansible_automation:
56+
host: name or ip of AWX/Tower/AAP host
57+
http_proto: http or https
58+
http_port: 80 or whatever
59+
ssl_verify: false # or true
60+
username: awx_user # should have permissions to view both projects and templates
61+
password: awx_password
62+
project_name: netbox-proxmox-ee-test1 # or whatever you named your project
63+
```
64+
65+
Usage:
66+
67+
```
68+
shell$ cd setup
69+
70+
shell$ pwd
71+
/some/path/netbox-proxmox-automation/setup
72+
73+
shell$ python3 -m venv venv
74+
75+
shell$ source venv/bin/activate
76+
77+
(venv) shell$ pip install -r requirements.txt
78+
79+
(venv) shell$ ./netbox_setup_webhook_and_event_rules.py --config /path/to/your/configuration.yml
80+
```
81+
82+
Then verify that everything has been created. You can skip the rest of this document if so.
83+
2784
#### AWX/Tower/AAP Webhook
2885

2986
To use NetBox webhooks with AWX, each NetBox webhook for Proxmox VM management will point at a separate AWX (job) template. In AWX, each (job) template has a unique ID. When we execute a webhook in NetBox, in this case we're using AWX, the (NetBox) webhook will in turn point at the (job) template ID in AWX -- and tell AWX to launch the template, i.e. to run the automation.

docs/netbox-event-rules-and-webhooks-flask.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,61 @@ Regardless of whether you are using a Flask (or other) application for Proxmox a
2424

2525
As noted [here](#initial-configuration-flask-application-python), you will need to have a running Flask application *before* you can start handling events (i.e. object changes) inside of NetBox.
2626

27+
#### Automated Webhook and Event Rules Configuration
28+
29+
If you'd prefer to manually create the webhook and event rules in NetBox, you can skip to the next section. Otherwise, proceed with the following to automate the creation of the webhook and event rules in NetBox.
30+
31+
`netbox-proxmox-automation` version 1.1.0 and newer ships with a convenience script, `netbox_setup_webhook_and_event_rules.py`, that when used alongside a configuration file of your choice, will greatly simplify this process.
32+
33+
There exists a sample configuration file called `netbox_setup_objects.yml-sample` under the conf.d directory of this git repository. Copy this file to a location of your choice, and season it to taste. In the end you should have a configuration that looks something like this.
34+
35+
```
36+
proxmox_api_config:
37+
api_host: proxmox-ip-or-hostname
38+
api_port: 8006
39+
api_user: proxmox_api_user
40+
api_token_id: name_of_proxmox_api_token
41+
api_token_secret: proxmox_api_secret_token
42+
verify_ssl: false
43+
netbox_api_config:
44+
api_proto: http # or https
45+
api_host: name or ip of NetBox host
46+
api_port: 8000
47+
api_token: netbox_api_secret_token
48+
verify_ssl: false # or true, up to you
49+
proxmox:
50+
cluster_name: proxmox-ve
51+
netbox:
52+
cluster_role: Proxmox
53+
vm_role: "Proxmox VM"
54+
automation_type: flask_application
55+
flask_application:
56+
host: name or ip of where Flask application is running
57+
http_proto: http or https
58+
http_port: 9000 or whatever
59+
ssl_verify: false # or true
60+
netbox_webhook_name: "netbox-proxmox-webhook"
61+
```
62+
63+
Usage:
64+
65+
```
66+
shell$ cd setup
67+
68+
shell$ pwd
69+
/some/path/netbox-proxmox-automation/setup
70+
71+
shell$ python3 -m venv venv
72+
73+
shell$ source venv/bin/activate
74+
75+
(venv) shell$ pip install -r requirements.txt
76+
77+
(venv) shell$ ./netbox_setup_webhook_and_event_rules.py --config /path/to/your/configuration.yml
78+
```
79+
80+
Then verify that everything has been created. You can skip the rest of this document if so.
81+
2782
#### Flask Application: Webhook
2883

2984
`example-netbox-webhook-flask-app` implements a catch-all for virtual machine events that happen in NetBox. Events will call the webhook, and in turn the webhook will dispatch Proxmox VM changes via the Proxmox API.

example-netbox-webhook-flask-app/app.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
import json
33
import yaml
44

5+
from datetime import datetime
6+
57
# adapted from: https://majornetwork.net/2019/10/webhook-listener-for-netbox/
68

79
from helpers.netbox_proxmox import NetBoxProxmoxHelper
810

9-
from flask import Flask, request
11+
from flask import Flask, request, jsonify
1012
from flask_restx import Api, Resource, fields
1113

14+
VERSION = '1.1.0'
15+
1216
app_config_file = 'app_config.yml'
1317

1418
with open(app_config_file) as yaml_cfg:
@@ -50,7 +54,33 @@
5054
'request_id': fields.String,
5155
})
5256

57+
# For session logging, c/o sol1
58+
session = {
59+
'name': "example-netbox-webhook-flask-app",
60+
'version': VERSION,
61+
'version_lastrun': VERSION,
62+
'server_start': "",
63+
'status': {
64+
'requests': 0,
65+
'last_called': ""
66+
},
67+
}
68+
69+
70+
@ns.route("/status/", methods=['GET'])
71+
class WebhookListener(Resource):
72+
@ns.expect(webhook_request)
73+
74+
def get(self):
75+
_session = session.copy()
76+
_session['version_lastrun'] = VERSION
77+
_session['status']['requests'] += 1
78+
_session['status']['last_called'] = datetime.now()
79+
logger.info(f"{request.full_path}, {request.remote_addr}, Status request with data {request.get_data()}")
80+
return jsonify(_session)
81+
5382

83+
# For handling event rules
5484
@ns.route("/")
5585
class WebhookListener(Resource):
5686
@ns.expect(webhook_request)

legacy/README.TXT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Simply put, don't use this stuff. It's just parked here and will be reimagined at some point in time.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)