Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
fix: change the way of creating host name which is an id in the datab…
Browse files Browse the repository at this point in the history
…ase (#104)
  • Loading branch information
omrozowicz-splunk authored Aug 24, 2021
1 parent c855088 commit bbf2733
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion splunk_connect_for_snmp_poller/manager/poller_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from splunk_connect_for_snmp_poller.manager.realtime.real_time_data import (
should_redo_walk,
)
from splunk_connect_for_snmp_poller.manager.task_utilities import parse_port
from splunk_connect_for_snmp_poller.manager.tasks import snmp_polling
from splunk_connect_for_snmp_poller.manager.validator.inventory_validator import (
is_valid_inventory_line_from_dict,
Expand Down Expand Up @@ -132,7 +133,10 @@ def _update_mongo(
all_walked_hosts_collection, host, host_already_walked, current_sys_up_time
):
if not host_already_walked:
all_walked_hosts_collection.add_host(host)
_host, _port = parse_port(host)
host_to_add = f"{_host}:{_port}"
logger.info(f"Adding host: {host_to_add} into Mongo database")
all_walked_hosts_collection.add_host(host_to_add)
all_walked_hosts_collection.update_real_time_data_for(host, current_sys_up_time)


Expand Down
7 changes: 6 additions & 1 deletion splunk_connect_for_snmp_poller/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import logging
import os

from pymongo import MongoClient, ReturnDocument
from pymongo.errors import ConnectionFailure

from splunk_connect_for_snmp_poller.manager.realtime.interface_mib import InterfaceMib

logger = logging.getLogger(__name__)

"""
In order to store some general data into Mongo we use the following structure.
Each WalkedHostsRepository can contain the following fields:
Expand Down Expand Up @@ -117,6 +120,9 @@ def real_time_data_for(self, host):

def static_data_for(self, host):
full_collection = self._walked_hosts.find_one({"_id": host})
if not full_collection:
logger.info(f"No id {host} in walked_host collection")
return None
if WalkedHostsRepository.MIB_STATIC_DATA in full_collection:
mib_static_data = full_collection[WalkedHostsRepository.MIB_STATIC_DATA]
if InterfaceMib.IF_MIB_DATA_MONGO_IDENTIFIER in mib_static_data:
Expand Down Expand Up @@ -147,6 +153,5 @@ def update_mib_static_data_for(self, host, if_mib_data):
self._walked_hosts.find_one_and_update(
{"_id": host},
{"$set": real_time_data_dictionary},
upsert=True,
return_document=ReturnDocument.AFTER,
)

0 comments on commit bbf2733

Please sign in to comment.