Secrets & Global Site Configuration
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,2 +1,5 @@
|
|||||||
I-Sight_Generated_Files*
|
I-Sight_Generated_Files*
|
||||||
DATAMODEL_*
|
DATAMODEL_*
|
||||||
|
.env
|
||||||
|
DEV_L_MYRTLE.xlsx
|
||||||
|
global_config.log
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1,8 +1,12 @@
|
|||||||
from azure.iot.hub import IoTHubRegistryManager
|
from azure.iot.hub import IoTHubRegistryManager
|
||||||
from azure.iot.hub.protocol.models import QuerySpecification
|
from azure.iot.hub.protocol.models import QuerySpecification
|
||||||
from azure.iot.hub.models import CloudToDeviceMethod, CloudToDeviceMethodResult
|
from azure.iot.hub.models import CloudToDeviceMethod, CloudToDeviceMethodResult
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
module_id = "thingspro-agent"
|
module_id = "thingspro-agent"
|
||||||
method_name = "thingspro-api-v1"
|
method_name = "thingspro-api-v1"
|
||||||
@@ -12,18 +16,29 @@ payload = '{"method":"GET", "path":"/device/general"}'
|
|||||||
# pip install azure-iot-hub
|
# pip install azure-iot-hub
|
||||||
|
|
||||||
# Authenticate to your Azure account
|
# Authenticate to your Azure account
|
||||||
CONNECTION_STRING = "HostName=IotHub-CUBE-PROD.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=...="
|
CONNECTION_STRING = str(os.getenv("CONNECTION_STRING_SAFT_PROD"))
|
||||||
|
# CONNECTION_STRING = str(os.getenv("CONNECTION_STRING_INOX_PROD"))
|
||||||
if CONNECTION_STRING == "":
|
if CONNECTION_STRING == "":
|
||||||
print("Provide a connection string for the Iot Hub before running the script!")
|
print("Provide a connection string for the Iot Hub before running the script!")
|
||||||
exit(13)
|
exit(13)
|
||||||
|
|
||||||
|
|
||||||
registry_manager = IoTHubRegistryManager.from_connection_string(CONNECTION_STRING)
|
registry_manager = IoTHubRegistryManager.from_connection_string(CONNECTION_STRING)
|
||||||
query_spec = QuerySpecification(query="SELECT * FROM devices WHERE tags.site = 'MYRTLE' AND tags.number != '0' AND capabilities.iotEdge = true")
|
query_spec = QuerySpecification(query="SELECT * FROM devices WHERE IS_DEFINED(tags.site) AND capabilities.iotEdge = true")
|
||||||
|
|
||||||
query_result = registry_manager.query_iot_hub(query_spec)
|
query_result = registry_manager.query_iot_hub(query_spec)
|
||||||
devices = []
|
devices = []
|
||||||
for item in query_result.items:
|
for item in query_result.items:
|
||||||
|
number = int(-1)
|
||||||
|
deviceId = "null"
|
||||||
|
site = "null"
|
||||||
|
if item.tagss['number']:
|
||||||
|
number = int(item.tags['number'])
|
||||||
|
if item.tags['deviceId']:
|
||||||
|
deviceId = item.tags['deviceId']
|
||||||
|
if item.tags['site']:
|
||||||
|
site = item.tags['site']
|
||||||
|
|
||||||
devices.append([int(item.tags['number']), item.tags['deviceId'], item.tags['site']])
|
devices.append([int(item.tags['number']), item.tags['deviceId'], item.tags['site']])
|
||||||
|
|
||||||
ordered_devices = sorted(devices, key = lambda x: (x[2], x[0]))
|
ordered_devices = sorted(devices, key = lambda x: (x[2], x[0]))
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ import requests
|
|||||||
from urllib3.exceptions import InsecureRequestWarning
|
from urllib3.exceptions import InsecureRequestWarning
|
||||||
import jq
|
import jq
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
# Function to authenticate and get token
|
# Function to authenticate and get token
|
||||||
def authenticate(device_ip, payload):
|
def authenticate(device_ip, payload):
|
||||||
@@ -106,10 +110,13 @@ def get_API_1(device_ip, token):
|
|||||||
|
|
||||||
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
||||||
|
|
||||||
|
default_user = str(os.getenv("DEFAULT_MOXA_USER"))
|
||||||
|
default_password = str(os.getenv("DEFAULT_MOXA_PASSWORD"))
|
||||||
|
|
||||||
payload_auth = {
|
payload_auth = {
|
||||||
"acceptEULA": True,
|
"acceptEULA": True,
|
||||||
"name": "",
|
"name": default_user,
|
||||||
"password": ""
|
"password": default_password
|
||||||
}
|
}
|
||||||
if payload_auth["name"] == "" or payload_auth["password"] == "":
|
if payload_auth["name"] == "" or payload_auth["password"] == "":
|
||||||
print("Provide the credentials before running the script!")
|
print("Provide the credentials before running the script!")
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ import requests
|
|||||||
from urllib3.exceptions import InsecureRequestWarning
|
from urllib3.exceptions import InsecureRequestWarning
|
||||||
import jq
|
import jq
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
# Function to authenticate and get token
|
# Function to authenticate and get token
|
||||||
def authenticate(device_ip, payload):
|
def authenticate(device_ip, payload):
|
||||||
@@ -275,13 +279,15 @@ requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
|||||||
# get_API(device_ip_address_https, token)
|
# get_API(device_ip_address_https, token)
|
||||||
# print("\n")
|
# print("\n")
|
||||||
|
|
||||||
|
default_user = str(os.getenv("DEFAULT_MOXA_USER"))
|
||||||
|
default_password = str(os.getenv("DEFAULT_MOXA_PASSWORD"))
|
||||||
|
|
||||||
for i in range(193, 222):
|
for i in range(193, 222):
|
||||||
upgrade_url = "https://files.thingsprocloud.com/package/Upgrade_AIG-301_2.4.0-4020_IMG_1.4_to_1.5.deb.yaml"
|
upgrade_url = "https://files.thingsprocloud.com/package/Upgrade_AIG-301_2.4.0-4020_IMG_1.4_to_1.5.deb.yaml"
|
||||||
payload_auth = {
|
payload_auth = {
|
||||||
"acceptEULA": True,
|
"acceptEULA": True,
|
||||||
"name": "admin",
|
"name": default_user,
|
||||||
"password": "admin@123"
|
"password": default_password
|
||||||
}
|
}
|
||||||
|
|
||||||
device_ip_address = str("10.84.171." + str(i))
|
device_ip_address = str("10.84.171." + str(i))
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ from urllib3.exceptions import InsecureRequestWarning
|
|||||||
import json
|
import json
|
||||||
import scp
|
import scp
|
||||||
import paramiko
|
import paramiko
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
def scp_file(local_path, remote_path, hostname, username, password):
|
def scp_file(local_path, remote_path, hostname, username, password):
|
||||||
try:
|
try:
|
||||||
@@ -78,13 +82,16 @@ def ssh_execute_command_with_password(hostname, username, password, command):
|
|||||||
|
|
||||||
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
|
||||||
|
|
||||||
|
default_user = str(os.getenv("DEFAULT_MOXA_SSH_USER"))
|
||||||
|
default_password = str(os.getenv("DEFAULT_MOXA_SSH_PASSWORD"))
|
||||||
|
|
||||||
local_file_path = "AIG-301_1.5.2-20240625_saft1_armhf.deb"
|
local_file_path = "AIG-301_1.5.2-20240625_saft1_armhf.deb"
|
||||||
if local_file_path == "":
|
if local_file_path == "":
|
||||||
print("Provide upgrade file path before running the script!")
|
print("Provide upgrade file path before running the script!")
|
||||||
exit(12)
|
exit(12)
|
||||||
remote_file_path = "./."
|
remote_file_path = "./."
|
||||||
username = "moxa"
|
username = default_user
|
||||||
password = "moxa"
|
password = default_password
|
||||||
if username == "" or password == "":
|
if username == "" or password == "":
|
||||||
print("Provide credentials before running the script!")
|
print("Provide credentials before running the script!")
|
||||||
exit(10)
|
exit(10)
|
||||||
|
|||||||
@@ -73,5 +73,5 @@ def main(folder_path):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
folder_path = '/mnt/c/Users/QWPHR/Downloads/JSON_BUFFER_7'
|
folder_path = ''
|
||||||
main(folder_path)
|
main(folder_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user