From 9ddfd86b4f54ba3f178fde9f8cb959baa02da718 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 22 Mar 2018 02:15:07 +0100 Subject: Commit diverse av Ole Mathias sitt template-greier --- include/config.pm | 94 ------------------------------------------ include/config.pm.dist | 94 ++++++++++++++++++++++++++++++++++++++++++ templating/templating.py | 2 +- web/api/read/distro-management | 2 +- web/api/read/networks | 0 web/api/write/network-add | 0 web/api/write/network-update | 0 web/index.html | 10 ++--- web/js/nms-template.js | 76 +++++++++++++++++++++------------- web/templates/HOWTO.txt | 2 +- 10 files changed, 149 insertions(+), 131 deletions(-) delete mode 100755 include/config.pm create mode 100755 include/config.pm.dist mode change 100644 => 100755 web/api/read/networks mode change 100644 => 100755 web/api/write/network-add mode change 100644 => 100755 web/api/write/network-update diff --git a/include/config.pm b/include/config.pm deleted file mode 100755 index dcc784d..0000000 --- a/include/config.pm +++ /dev/null @@ -1,94 +0,0 @@ -#! /usr/bin/perl -use strict; -use warnings; -package nms::config; - -# DB -our $db_name = "nms"; -our $db_host = "localhost"; -our $db_username = "nms"; -our $db_password = "risbrod"; -our $graphite_host = "graphite"; -our $graphite_port = "2003"; - -# Influx -our $influx_host = "http://localhost:8086"; -our $influx_username = "gondulWrite"; -our $influx_password = "funfunfunWrite"; -our $influx_database = "gondul"; - -# Max SNMP polls to fire off at the same time. -our $snmp_max = 20; - -# What SNMP objects to fetch. -our @snmp_objects = [ - ['ifIndex'], - ['sysName'], - ['sysDescr'], - ['ifHighSpeed'], - ['ifType'], - ['ifName'], - ['ifDescr'], - ['ifAlias'], - ['ifOperStatus'], - ['ifAdminStatus'], - ['ifLastChange'], - ['ifPhysAddress'], - ['ifHCInOctets'], - ['ifHCOutOctets'], - ['ifInDiscards'], - ['ifOutDiscards'], - ['ifInErrors'], - ['ifOutErrors'], - ['ifInUnknownProtos'], - ['ifOutQLen'], - ['sysUpTime'], - ['ciscoEnvMonTemperatureStatusValue'], - ['ipIfStatsHCInOctets'], - ['ipIfStatsHCOutOctets'], - ['ipIfStatsIPVersion'], - ['entPhysicalSerialNum'], - ['entPhysicalName'], - ['entPhysicalHardwareRev'], - ['entPhysicalFirmwareRev'], - ['entPhysicalSoftwareRev'], - ['entPhysicalDescr'], - ['jnxOperatingTemp'], - ['jnxOperatingCPU'], - ['jnxOperatingDescr'], - ['jnxBoxSerialNo'], - ['jnxVirtualChassisFpcId'], - ['jnxVirtualChassisPortName'], - ['jnxVirtualChassisPortAdminStatus'], - ['jnxVirtualChassisPortOperStatus'], - ['jnxVirtualChassisPortInPkts'], - ['jnxVirtualChassisPortOutPkts'], - ['jnxVirtualChassisPortInOctets'], - ['jnxVirtualChassisPortOutOctets'], - ['jnxVirtualChassisPortInMcasts'], - ['jnxVirtualChassisPortOutMcasts'], - ['jnxVirtualChassisPortInPkts1secRate'], - ['jnxVirtualChassisPortOutPkts1secRate'], - ['jnxVirtualChassisPortInOctets1secRate'], - ['jnxVirtualChassisPortOutOctets1secRate'], - ['jnxVirtualChassisPortCarrierTrans'], - ['jnxVirtualChassisPortInCRCAlignErrors'], - ['jnxVirtualChassisPortUndersizePkts'], - ['jnxVirtualChassisPortCollisions'], - ['jnxVirtualChassisMemberFabricMode'], - ['jnxVirtualChassisMemberLocation'], - ['jnxVirtualChassisMemberMixedMode'], - ['jnxVirtualChassisMemberModel'], - ['jnxVirtualChassisMemberPriority'], - ['jnxVirtualChassisMemberRole'], - ['jnxVirtualChassisMemberSerialnumber'], - ['jnxVirtualChassisMemberSWVersion'], - ['jnxVirtualChassisMemberUptime'] -]; - -BEGIN { - eval { - require "/opt/gondul/include/config.local.pm"; - }; -} -1; diff --git a/include/config.pm.dist b/include/config.pm.dist new file mode 100755 index 0000000..78f03cc --- /dev/null +++ b/include/config.pm.dist @@ -0,0 +1,94 @@ +#! /usr/bin/perl +use strict; +use warnings; +package nms::config; + +# DB +our $db_name = "nms"; +our $db_host = "localhost"; +our $db_username = "nms"; +our $db_password = "risbrod"; +our $graphite_host = "graphite"; +our $graphite_port = "2003"; + +# Influx +our $influx_host = "http://localhost:8086"; +our $influx_username = "gondulWrite"; +our $influx_password = "pasr"; +our $influx_database = "gondul"; + +# Max SNMP polls to fire off at the same time. +our $snmp_max = 20; + +# What SNMP objects to fetch. +our @snmp_objects = [ + ['ifIndex'], + ['sysName'], + ['sysDescr'], + ['ifHighSpeed'], + ['ifType'], + ['ifName'], + ['ifDescr'], + ['ifAlias'], + ['ifOperStatus'], + ['ifAdminStatus'], + ['ifLastChange'], + ['ifPhysAddress'], + ['ifHCInOctets'], + ['ifHCOutOctets'], + ['ifInDiscards'], + ['ifOutDiscards'], + ['ifInErrors'], + ['ifOutErrors'], + ['ifInUnknownProtos'], + ['ifOutQLen'], + ['sysUpTime'], + ['ciscoEnvMonTemperatureStatusValue'], + ['ipIfStatsHCInOctets'], + ['ipIfStatsHCOutOctets'], + ['ipIfStatsIPVersion'], + ['entPhysicalSerialNum'], + ['entPhysicalName'], + ['entPhysicalHardwareRev'], + ['entPhysicalFirmwareRev'], + ['entPhysicalSoftwareRev'], + ['entPhysicalDescr'], + ['jnxOperatingTemp'], + ['jnxOperatingCPU'], + ['jnxOperatingDescr'], + ['jnxBoxSerialNo'], + ['jnxVirtualChassisFpcId'], + ['jnxVirtualChassisPortName'], + ['jnxVirtualChassisPortAdminStatus'], + ['jnxVirtualChassisPortOperStatus'], + ['jnxVirtualChassisPortInPkts'], + ['jnxVirtualChassisPortOutPkts'], + ['jnxVirtualChassisPortInOctets'], + ['jnxVirtualChassisPortOutOctets'], + ['jnxVirtualChassisPortInMcasts'], + ['jnxVirtualChassisPortOutMcasts'], + ['jnxVirtualChassisPortInPkts1secRate'], + ['jnxVirtualChassisPortOutPkts1secRate'], + ['jnxVirtualChassisPortInOctets1secRate'], + ['jnxVirtualChassisPortOutOctets1secRate'], + ['jnxVirtualChassisPortCarrierTrans'], + ['jnxVirtualChassisPortInCRCAlignErrors'], + ['jnxVirtualChassisPortUndersizePkts'], + ['jnxVirtualChassisPortCollisions'], + ['jnxVirtualChassisMemberFabricMode'], + ['jnxVirtualChassisMemberLocation'], + ['jnxVirtualChassisMemberMixedMode'], + ['jnxVirtualChassisMemberModel'], + ['jnxVirtualChassisMemberPriority'], + ['jnxVirtualChassisMemberRole'], + ['jnxVirtualChassisMemberSerialnumber'], + ['jnxVirtualChassisMemberSWVersion'], + ['jnxVirtualChassisMemberUptime'] +]; + +BEGIN { + eval { + require "/opt/gondul/include/config.local.pm"; + }; +} +1; diff --git a/templating/templating.py b/templating/templating.py index 9794655..60b2616 100755 --- a/templating/templating.py +++ b/templating/templating.py @@ -6,7 +6,7 @@ import json import http.server from enum import Enum -endpoints = "read/oplog read/snmp read/switches-management public/config public/dhcp public/dhcp-summary public/ping public/switches public/switch-state".split() +endpoints = "read/networks read/oplog read/snmp read/switches-management public/distro-tree public/config public/dhcp public/dhcp-summary public/ping public/switches public/switch-state".split() objects = dict() def getEndpoint(endpoint): diff --git a/web/api/read/distro-management b/web/api/read/distro-management index 7fbebef..55ca07e 100755 --- a/web/api/read/distro-management +++ b/web/api/read/distro-management @@ -19,7 +19,7 @@ my $q2; $nms::web::cc{'max-age'} = "5"; $nms::web::cc{'stale-while-revalidate'} = "30"; -$q2 = $nms::web::dbh->prepare('SELECT distro_name,sysname,subnet4,subnet6,traffic_vlan,distro_phy_port FROM switches WHERE placement is not null AND distro_name is not null AND distro_phy_port is not null and deleted = false'); +$q2 = $nms::web::dbh->prepare('SELECT distro_name,sysname,distro_phy_port FROM switches WHERE placement is not null AND distro_name is not null AND distro_phy_port is not null and deleted = false'); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { diff --git a/web/api/read/networks b/web/api/read/networks old mode 100644 new mode 100755 diff --git a/web/api/write/network-add b/web/api/write/network-add old mode 100644 new mode 100755 diff --git a/web/api/write/network-update b/web/api/write/network-update old mode 100644 new mode 100755 diff --git a/web/index.html b/web/index.html index d8f2a60..2fee54f 100644 --- a/web/index.html +++ b/web/index.html @@ -143,11 +143,11 @@
-
- - - -
+
+ +
diff --git a/web/js/nms-template.js b/web/js/nms-template.js index c34ef34..6159f5b 100644 --- a/web/js/nms-template.js +++ b/web/js/nms-template.js @@ -4,36 +4,54 @@ var nmsTemplate = nmsTemplate || { } nmsTemplate.test = function() { - var input = document.getElementById("template-input"); - var output = document.getElementById("template-output"); - var qp = document.getElementById("template-query-params"); - $.ajax({ - type: "POST", - url: "/api/templates/test" + qp.value, - async: false, - data: input.value, - dataType: "text", - success: function (indata, textStatus, jqXHR) { - var output = document.getElementById("template-output"); - output.value = jqXHR.responseText; - }, - error: function (jqXHR, textStatus) { - var output = document.getElementById("template-output"); - output.value = jqXHR.responseText; - } - }); + var input = document.getElementById("template-input"); + var output = document.getElementById("template-output"); + var qp = document.getElementById("template-query-params"); + $.ajax({ + type: "POST", + url: "/api/templates/test" + qp.value, + async: false, + data: input.value, + dataType: "text", + success: function (indata, textStatus, jqXHR) { + var output = document.getElementById("template-output"); + output.value = jqXHR.responseText; + }, + error: function (jqXHR, textStatus) { + var output = document.getElementById("template-output"); + output.value = jqXHR.responseText; + } + }); } nmsTemplate.fromFile = function(template) { - $.ajax({ - type: "GET", - url: "/templates/" + template, - async: false, - dataType: "text", - success: function (indata, textStatus, jqXHR) { - var output = document.getElementById("template-input"); - output.value = indata; - } - }); - nmsTemplate.test(); + if(template == '') { return; } + $.ajax({ + type: "GET", + url: "/templates/" + template, + async: false, + dataType: "text", + success: function (indata, textStatus, jqXHR) { + var output = document.getElementById("template-input"); + output.value = indata; + } + }); + nmsTemplate.test(); } + +nmsTemplate.getTemplates = function() { + $.ajax({ + type: "GET", + url: "/api/read/template-list", + async: false, + dataType: "json", + success: function (indata, textStatus, jqXHR) { + console.log(indata['templates']); + $.each( indata['templates'], function( value ) { + $('#nmsTemplate-select').append($("").attr("value",indata['templates'][value]['file']).text(indata['templates'][value]['file'])); + }); + } + }); +} + +nmsTemplate.getTemplates(); diff --git a/web/templates/HOWTO.txt b/web/templates/HOWTO.txt index ed47926..641878e 100644 --- a/web/templates/HOWTO.txt +++ b/web/templates/HOWTO.txt @@ -8,7 +8,7 @@ We utilize Jinja2 templates. -#} {% set url = "localhost" -%} -{% set example_switch = "distro0" -%} +{% set example_switch = "r1.tele" -%} See http://jinja.pocoo.org/ for the full documentation of the templating language. -- cgit v1.2.3