lib/imperituroard/projects/iot/mongoconnector.rb in imperituroard-0.2.5 vs lib/imperituroard/projects/iot/mongoconnector.rb in imperituroard-0.2.7
- old
+ new
@@ -16,19 +16,19 @@
@mongo_port = mongo_port
client_host = [mongo_ip + ":" + mongo_port]
@client = Mongo::Client.new(client_host, :database => mongo_database)
end
- def audit_logger(proc_name, src_ip, input_json, output_json)
+ def audit_logger(proc_name, src_ip, input_json, output_json, real_ip)
begin
d = DateTime.now
current = d.strftime("%d/%m/%Y %H:%M:%S")
collection = client[:audit]
doc = {
:proc_name => proc_name,
:date => current,
- :sender => {:src_ip => src_ip},
+ :sender => {:src_ip => src_ip, :real_ip => real_ip},
:input_params => input_json,
:output_params => output_json
}
result = collection.insert_one(doc)
return {:code => 200, :result => "Request completed successfully", :body => result}
@@ -205,12 +205,12 @@
collection = client[:device_imei]
p imei_list
for l in imei_list
doc = {
imei: l,
- imsi: "",
- msisdn: "",
+ imsi: "unknown",
+ msisdn: "unknown",
description: "test imei",
note: "second description",
profile: 0,
type: 0,
address: "unknown"
@@ -221,10 +221,34 @@
rescue
continue
end
end
+
+ def imei_insert_list2(imei_list)
+ begin
+ collection = client[:device_imei]
+ p imei_list
+ for l in imei_list
+ doc = {
+ imei: l,
+ imsi: "unknown",
+ msisdn: "unknown",
+ description: "test imei",
+ note: "second description",
+ profile: 0,
+ type: 0,
+ address: "unknown"
+ }
+ result = collection.insert_one(l)
+ p result
+ end
+ rescue
+ continue
+ end
+ end
+
def get_profile_name_from_imei(imei)
begin
begin
info = get_imei_info_from_db([imei])
if info[:body]==[]
@@ -304,9 +328,27 @@
p result
rescue
continue
end
end
+
+
+ def get_iot_oceanconnect_credent(login)
+ begin
+ result_ps = []
+ collection = client[:users]
+ collection.find({"login" => login}).each {|row|
+ result_ps.append(row)
+ }
+ p result_ps[0]
+ app_id = result_ps[0][:iot_data][:app_id]
+ secret = result_ps[0][:iot_data][:secret]
+ return {:code => 200, :result => "get_iot_oceanconnect_credent: Request completed successfully", :body => {:app_id => app_id, :secret => secret}}
+ rescue
+ {:code => 500, :result => "get_iot_oceanconnect_credent: Process failed"}
+ end
+
+ end
def ttt
p "111111"
begin
\ No newline at end of file