Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
python_wiki:django_configuration [2018/08/01 20:44] billdozor [Page Content: Stats] |
python_wiki:django_configuration [2019/05/25 23:50] (current) |
||
---|---|---|---|
Line 3: | Line 3: | ||
**General Information** | **General Information** | ||
- | Configuring the Django Web Framework and its dependencies. | + | Configuring the Django Web Framework and its dependencies. |
+ | \\ | ||
+ | The **EXAMPLE** sections of code end up building an inventory website. | ||
+ | |||
+ | \\ | ||
**Checklist** | **Checklist** | ||
* [[python_wiki: | * [[python_wiki: | ||
Line 24: | Line 28: | ||
* Run secure setup< | * Run secure setup< | ||
* Prompts for the following: | * Prompts for the following: | ||
+ | * Current password for root (should be none, just press enter) | ||
* Set database root password | * Set database root password | ||
* Remove anonymous users | * Remove anonymous users | ||
Line 46: | Line 51: | ||
Configuring Django. | Configuring Django. | ||
- | * Verify django works< | + | * Verify django works< |
>>> | >>> | ||
>>> | >>> | ||
Line 113: | Line 118: | ||
#asset_type choices | #asset_type choices | ||
DEVICE_TYPES = ( | DEVICE_TYPES = ( | ||
- | ('Firewall', 'Firewall'), | + | ('Firewalls', 'Firewalls'), |
- | ('Router', 'Router'), | + | ('Routers', 'Routers'), |
- | ('Server', 'Server' | + | ('Servers', 'Servers' |
(' | (' | ||
- | ('Switch', 'Switch'), | + | ('Switches', 'Switches'), |
- | ('Workstation', 'Workstation'), | + | ('Workstations', 'Workstations'), |
) | ) | ||
Line 128: | Line 133: | ||
) | ) | ||
- | # asset_os choices | + | # Linux OS List |
- | | + | |
(' | (' | ||
(' | (' | ||
- | (' | ||
- | (' | ||
- | (' | ||
- | (' | ||
- | (' | ||
('RHEL 6', 'Red Hat Enterprise Linux 6' | ('RHEL 6', 'Red Hat Enterprise Linux 6' | ||
('RHEL 7', 'Red Hat Enterprise Linux 7' | ('RHEL 7', 'Red Hat Enterprise Linux 7' | ||
(' | (' | ||
(' | (' | ||
- | (' | + | |
+ | |||
+ | # Windows OS List | ||
+ | OS_NAMES_WINDOWS = ( | ||
('Win 2008', ' | ('Win 2008', ' | ||
('Win 2012', ' | ('Win 2012', ' | ||
Line 148: | Line 151: | ||
('Win 10', ' | ('Win 10', ' | ||
) | ) | ||
+ | |||
+ | # Other OS List | ||
+ | OS_NAMES_OTHER = ( | ||
+ | (' | ||
+ | (' | ||
+ | (' | ||
+ | (' | ||
+ | (' | ||
+ | (' | ||
+ | ) | ||
+ | |||
+ | # Combined OS List - for asset_os choices | ||
+ | OS_NAMES = OS_NAMES_LINUX + OS_NAMES_WINDOWS + OS_NAMES_OTHER | ||
# asset_hardware choices | # asset_hardware choices | ||
Line 220: | Line 236: | ||
* Create logging directory and setup ownership/ | * Create logging directory and setup ownership/ | ||
chown :apache / | chown :apache / | ||
- | chmod g+rwx / | + | chmod g+rwxs / |
===== Admin Interface ===== | ===== Admin Interface ===== | ||
Line 226: | Line 242: | ||
* Create an admin user< | * Create an admin user< | ||
- | * Make your models/ | + | * Make your models/ |
from __future__ import unicode_literals | from __future__ import unicode_literals | ||
Line 279: | Line 295: | ||
url(r' | url(r' | ||
- | # /myapphere/device/ - Specific Device, All Environments | + | # /myapphere/device_type/ - Specific Device, All Environments |
- | url(r' | + | url(r' |
- | # /myapphere/device/ | + | # /myapphere/device_type/ |
- | url(r' | + | url(r' |
+ | |||
+ | # / | ||
+ | url(r' | ||
]</ | ]</ | ||
Line 334: | Line 353: | ||
asset_type_list = [key for key,value in AssetEntry.DEVICE_TYPES] | asset_type_list = [key for key,value in AssetEntry.DEVICE_TYPES] | ||
- | # Get all os names | + | # Get all os names, Linux only, Windows only |
os_list = [key for key,value in AssetEntry.OS_NAMES] | os_list = [key for key,value in AssetEntry.OS_NAMES] | ||
+ | os_list_linux = [key for key,value in AssetEntry.OS_NAMES_LINUX] | ||
+ | os_list_windows = [key for key,value in AssetEntry.OS_NAMES_WINDOWS] | ||
# Log for debug purposes | # Log for debug purposes | ||
Line 350: | Line 371: | ||
sysstats_grand_physical_linux = 0 | sysstats_grand_physical_linux = 0 | ||
sysstats_grand_physical_windows = 0 | sysstats_grand_physical_windows = 0 | ||
+ | sysstats_grand_physical_other = 0 | ||
sysstats_grand_virtual = 0 | sysstats_grand_virtual = 0 | ||
sysstats_grand_virtual_linux = 0 | sysstats_grand_virtual_linux = 0 | ||
sysstats_grand_virtual_windows = 0 | sysstats_grand_virtual_windows = 0 | ||
+ | sysstats_grand_virtual_other = 0 | ||
sysstats_grand_vmware = 0 | sysstats_grand_vmware = 0 | ||
Line 376: | Line 399: | ||
count_physical_linux = 0 | count_physical_linux = 0 | ||
count_physical_windows = 0 | count_physical_windows = 0 | ||
+ | count_physical_other = 0 | ||
count_virtual = 0 | count_virtual = 0 | ||
count_virtual_linux = 0 | count_virtual_linux = 0 | ||
count_virtual_windows = 0 | count_virtual_windows = 0 | ||
+ | count_virtual_other = 0 | ||
for node in device_stats: | for node in device_stats: | ||
if node.asset_hardware == " | if node.asset_hardware == " | ||
count_physical += 1 | count_physical += 1 | ||
- | if node.asset_os.startswith(" | + | if node.asset_os |
- | # Physical+Linux Count (include physical virtual vmware hosts) | + | # Physical+Linux Count |
count_physical_linux += 1 | count_physical_linux += 1 | ||
- | elif node.asset_os.startswith(" | + | elif node.asset_os |
# Physical+Windows Count | # Physical+Windows Count | ||
count_physical_windows += 1 | count_physical_windows += 1 | ||
+ | else: | ||
+ | # Physical+Other OS | ||
+ | count_physical_other += 1 | ||
elif node.asset_hardware == " | elif node.asset_hardware == " | ||
Line 394: | Line 422: | ||
count_virtual += 1 | count_virtual += 1 | ||
- | if node.asset_os.startswith(" | + | if node.asset_os |
# Virtual+Linux Count | # Virtual+Linux Count | ||
count_virtual_linux += 1 | count_virtual_linux += 1 | ||
- | elif node.asset_os.startswith(" | + | elif node.asset_os |
# Virtual+Windows Count | # Virtual+Windows Count | ||
count_virtual_windows += 1 | count_virtual_windows += 1 | ||
+ | else: | ||
+ | # Virtual+Other OS | ||
+ | count_virtual_other += 1 | ||
#- Add to grand total physical | #- Add to grand total physical | ||
Line 405: | Line 436: | ||
sysstats_grand_physical_linux += count_physical_linux | sysstats_grand_physical_linux += count_physical_linux | ||
sysstats_grand_physical_windows += count_physical_windows | sysstats_grand_physical_windows += count_physical_windows | ||
+ | sysstats_grand_physical_other += count_physical_other | ||
#- Add to grand total virtual | #- Add to grand total virtual | ||
Line 410: | Line 442: | ||
sysstats_grand_virtual_linux += count_virtual_linux | sysstats_grand_virtual_linux += count_virtual_linux | ||
sysstats_grand_virtual_windows += count_virtual_windows | sysstats_grand_virtual_windows += count_virtual_windows | ||
+ | sysstats_grand_virtual_other += count_virtual_other | ||
####---- OS Counts Table ----#### | ####---- OS Counts Table ----#### | ||
Line 430: | Line 463: | ||
####---- After All Stats Calculations: | ####---- After All Stats Calculations: | ||
# Add device statistics to stats_list | # Add device statistics to stats_list | ||
- | stats_list.append({ ' | + | stats_list.append({ ' |
# Grand Total Only: VMware ESXi Host Count | # Grand Total Only: VMware ESXi Host Count | ||
Line 458: | Line 491: | ||
####---- Add grand totals to stats_list ----#### | ####---- Add grand totals to stats_list ----#### | ||
- | stats_list.append({ ' | + | stats_list.append({ ' |
#- Other Grand Totals: Calculate -# | #- Other Grand Totals: Calculate -# | ||
sysstats_grand_linux = sysstats_grand_physical_linux + sysstats_grand_virtual_linux | sysstats_grand_linux = sysstats_grand_physical_linux + sysstats_grand_virtual_linux | ||
sysstats_grand_windows = sysstats_grand_physical_windows + sysstats_grand_virtual_windows | sysstats_grand_windows = sysstats_grand_physical_windows + sysstats_grand_virtual_windows | ||
+ | sysstats_grand_other = sysstats_grand_physical_other + sysstats_grand_virtual_other | ||
# Map template variable names (1st) to the Python variables (2nd) for use in templates | # Map template variable names (1st) to the Python variables (2nd) for use in templates | ||
- | context = {' | + | context = {' |
# Logging | # Logging | ||
Line 873: | Line 907: | ||
< | < | ||
<tr class=" | <tr class=" | ||
- | <th class=" | + | <th class=" |
<th class=" | <th class=" | ||
<th class=" | <th class=" | ||
<th class=" | <th class=" | ||
<th class=" | <th class=" | ||
- | <th class=" | + | <th class=" |
</tr> | </tr> | ||
</ | </ | ||
< | < | ||
- | {% for name in all_assets_list | + | {% for name in all_asset_list |
<tr class=" | <tr class=" | ||
<td class=" | <td class=" | ||
Line 1017: | Line 1051: | ||
<th class=" | <th class=" | ||
<th class=" | <th class=" | ||
+ | <th class=" | ||
<th class=" | <th class=" | ||
<th class=" | <th class=" | ||
<th class=" | <th class=" | ||
+ | <th class=" | ||
</tr> | </tr> | ||
</ | </ | ||
Line 1026: | Line 1062: | ||
<tr class=" | <tr class=" | ||
{% if asset.asset_type == ' | {% if asset.asset_type == ' | ||
- | <td class=" | + | <td class=" |
<td class=" | <td class=" | ||
<td class=" | <td class=" | ||
<td class=" | <td class=" | ||
<td class=" | <td class=" | ||
+ | <td class=" | ||
<td class=" | <td class=" | ||
<td class=" | <td class=" | ||
<td class=" | <td class=" | ||
+ | <td class=" | ||
{% else %} | {% else %} | ||
<td class=" | <td class=" | ||
Line 1040: | Line 1078: | ||
<td class=" | <td class=" | ||
<td class=" | <td class=" | ||
+ | <td class=" | ||
<td class=" | <td class=" | ||
<td class=" | <td class=" | ||
<td class=" | <td class=" | ||
+ | <td class=" | ||
{% endif %} | {% endif %} | ||
</tr> | </tr> | ||
Line 1053: | Line 1093: | ||
<td class=" | <td class=" | ||
<td class=" | <td class=" | ||
+ | </tr> | ||
+ | <tr class=" | ||
+ | <td class=" | ||
+ | <td class=" | ||
</tr> | </tr> | ||
<tr class=" | <tr class=" | ||
Line 1093: | Line 1137: | ||
<tr class=" | <tr class=" | ||
{% if asset.asset_type == ' | {% if asset.asset_type == ' | ||
- | <td class=" | + | <td class=" |
{% for name in asset.os_count_stats %} | {% for name in asset.os_count_stats %} | ||
<td class=" | <td class=" | ||
Line 1131: | Line 1175: | ||
* Create directory structure< | * Create directory structure< | ||
- | * Create stylesheet (/ | + | * Create stylesheet (/ |
/* ---- Table Styles ---- */ | /* ---- Table Styles ---- */ | ||
Line 1163: | Line 1207: | ||
/* tr -> table rows | /* tr -> table rows | ||
- | * tr: | + | |
- | * tr:hover -> Mouse hover background color effect */ | + | * * tr:hover -> Mouse hover background color effect */ |
tr.myapphere: | tr.myapphere: | ||
tr.myapphere: | tr.myapphere: | ||
Line 1179: | Line 1223: | ||
/* ---- Menu Styles ---- */ | /* ---- Menu Styles ---- */ | ||
- | ul.device | + | ul.asset_type |
list-style-type: | list-style-type: | ||
margin: 0; | margin: 0; | ||
Line 1185: | Line 1229: | ||
overflow: hidden; | overflow: hidden; | ||
background-color: | background-color: | ||
- | width: | + | width: |
} | } | ||
Line 1203: | Line 1247: | ||
overflow: hidden; | overflow: hidden; | ||
background-color: | background-color: | ||
- | width: | + | width: |
} | } | ||
- | ul.asset_type | + | ul.asset_hardware |
list-style-type: | list-style-type: | ||
margin: 0; | margin: 0; | ||
Line 1212: | Line 1256: | ||
overflow: hidden; | overflow: hidden; | ||
background-color: | background-color: | ||
- | width: | + | width: |
} | } | ||
Line 1507: | Line 1551: | ||
<a href="#" | <a href="#" | ||
+ | ---- | ||
+ | |||
+ | ====== Django: Static Files ====== | ||
+ | |||
+ | No matter which steps from above you skip, you absolutely need to collect static files to copy them into the location Apache expects them to be. | ||
+ | |||
+ | This is for Apache' | ||
* Collect static files< | * Collect static files< | ||
python manage.py collectstatic</ | python manage.py collectstatic</ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== DEBUG: TURN OFF ====== | ||
+ | |||
+ | Lastly, when you are not developing/ | ||
+ | |||
+ | \\ | ||
+ | Edit the project settings (/ | ||
+ | DEBUG = False</ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== Next Steps ======= | ||
+ | |||
+ | [[python_wiki: | ||
---- | ---- | ||