Commit 28acb8fc authored by ajil.k's avatar ajil.k

added

parents
import bson
import pymongo
# Set up a MongoDB client
client = pymongo.MongoClient('mongodb://ilens:ilens%401234@192.168.0.220:4720/?authSource=admin')
# Select the database and collection to restore
db = client["Iot_manager(Test)"]
col_list = ['mp201a', 'glens', 'ilens', 'ilens_ir4.0', 'dubai-munc', 'epda-rak', 'camw', 'ilens-avis', 'old_glens',
'old_calixto', "ilens-mc"]
for collection_name in col_list:
i = 0
collection = db[collection_name]
path = "C:/Users/ajil.k/Desktop/iot_devices/iot_devices/"
# Open the BSON file for reading
full_path_with_extension = f"{path}{collection_name}.bson"
with open(full_path_with_extension, "rb") as bson_file:
# Loop through each document in the BSON file and insert it into the collection
for document in bson.decode_file_iter(bson_file):
collection.insert_one(document)
i += 1
print(f"{collection_name} - {i}")
from datetime import datetime
from pydantic import BaseModel, Field
class DeviceDetails(BaseModel):
device_id: str = Field(default="", description="The ID of the device")
software_name: str = Field(default="", description="The name of the software running on the device")
mac_address: str = Field(default="", description="The MAC address of the device")
site_id: str = Field(default="", description="The ID of the site where the device is located")
site_name: str = Field(default="", description="The name of the site where the device is located")
site_location: dict = Field(default={"country": "", "state": "", "city": ""},
description="The location of the site where the device is located")
customer: str = Field(default="", description="The name of the customer that owns the device")
vendor: str = Field(default="", description="The name of the vendor that supplied the device")
tags: list[str] = Field(default=[], description="Any tags associated with the device")
class DeviceParameters(BaseModel):
mac_address: str = Field(default="", description="The MAC address of the device")
software_name: str = Field(default="", description="The name of the software running on the device")
ram_total: int = Field(default=0, description="The total amount of RAM on the device")
ram_percent: float = Field(default=0.00, description="The percentage of RAM used on the device")
ram_free: int = Field(default=0, description="The amount of free RAM on the device")
ram_used: int = Field(default=0, description="The amount of RAM used on the device")
disk: dict = Field(default={}, description="The details of the disk space on the device")
last_reboot: datetime
last_sync: datetime
throttle: str = Field(default="", description="The throttle status of the device")
io_count: dict = Field(default={"read_count": 0, "write_count": 0, "read_bytes": 0, "write_bytes": 0,
"read_time": 0, "write_time": 0, "read_merged_count": 0,
"write_merged_count": 0, "busy_time": 0},
description="The input/output count and time for the device")
public_ip: str = Field(default="", description="The public IP address of the device")
vpn_ip: str = Field(default="", description="The VPN IP address of the device")
vpn_connected: bool = Field(default=False, description="The status of VPN connection of the device")
firmware_version: str = Field(default="", description="The firmware version of the device")
app_version: list = Field(default=[], description="The app version of the device")
monitor_id: str = Field(default="", description="The monitor ID of the device")
monitoring_list: str = Field(default="", description="The monitoring list of the device")
cpu: dict = Field(default={"current": "", "overall_usage": "", "cpu_temp": "",
"each_cpu_usage": [0, 0]},
description="The CPU usage and temperature of the device")
rssi: str = Field(default="", description="The RSSI value of the device")
cts: int = Field(default=0, description="The CTS value of the device")
rts: int = Field(default=0, description="The RTS value of the device")
lts: int = Field(default=0, description="The LTS value of the device")
ats: int = Field(default=0, description="The ATS value of the device")
status: str = Field(default="", description="The status of the device")
clear_sd: bool = Field(default=False, description="The status of clearing the SD card of the device")
eth_ip: str = Field(default="", description="The Ethernet IP address of the device")
username: str = Field(default="", description="The username of the device")
date: str = Field(default="", description="The date of the device")
network_name: str = Field(default="", description="The network name of the device")
signal_quality: str = Field(default="", description="The signal quality of the device")
firmware: dict = Field(default={}, description="The firmware details of the device")
app: dict = Field(default={}, description="The app details of device")
try_count: int = Field(default=0, description="Try count details of device")
board_version: str = Field(default="", description="Board version of the device")
terminal: str = Field(default="", description="terminal url of the device")
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment