I'm trying to print only the value of a JSON and I'm getting the error no implicit conversion of String into Integer.
Any idea how I can resolve this?
puts test.class
Azure::Armrest::ArmrestCollection
Here is the output of the varaible and I want to print only the quantity value.
puts test
[----] I, [2022-08-23T08:59:20.279357 #550:bc494] INFO -- automation: Method STDOUT: {"id":"/subscriptions/123456/providers/Microsoft.Commerce/UsageAggregates/Daily_BRSDT_20220801_0000","name":"Daily_BRSDT_20220801_0000","type":"Microsoft.Commerce/UsageAggregate","properties":{"subscriptionId":"123456","usageStartTime":"2022-07-31T00:00:00+00:00","usageEndTime":"2022-08-01T00:00:00+00:00","meterName":"Data Transfer Out","meterRegion":"North America","meterCategory":"Bandwidth","meterSubCategory":"Inter-Region","unit":"1 GB","instanceData":"{\"Microsoft.Resources\":{\"resourceUri\":\"/subscriptions/123456/resourceGroups/cloud-shell-storage-centralindia/providers/Microsoft.Compute/virtualMachines/ubuntu975\",\"location\":\"eastus\",\"additionalInfo\":{\"PipelineType\":\"v2\",\"DataTransferDirection\":\"DataTrOut\"}}}","meterId":"dbefcfc1-e3f6-409b-be6d-9cd7b00724a5","infoFields":{},"quantity":9.052455425262451e-07}}
[----] I, [2022-08-23T08:59:20.280435 #550:bc494] INFO -- automation: Method STDOUT: {"id":"/subscriptions/123456/providers/Microsoft.Commerce/UsageAggregates/Daily_BRSDT_20220801_0000","name":"Daily_BRSDT_20220801_0000","type":"Microsoft.Commerce/UsageAggregate","properties":{"subscriptionId":"123456","usageStartTime":"2022-07-31T00:00:00+00:00","usageEndTime":"2022-08-01T00:00:00+00:00","meterName":"Dynamic Public IP","meterCategory":"Virtual Network","meterSubCategory":"IP Addresses","unit":"1 Hour","instanceData":"{\"Microsoft.Resources\":{\"resourceUri\":\"/subscriptions/123456/resourceGroups/cloud-shell-storage-centralindia/providers/Microsoft.Network/publicIPAddresses/Ubuntu975-publicIp\",\"location\":\"eastus\",\"additionalInfo\":{\"IpAddress\":\"20.25.57.9\",\"PlatformType\":\"V2-Agg\"}}}","meterId":"f114cb19-ea64-40b5-bcd7-aee474b62853","infoFields":{},"quantity":1.0}}
puts test["properties"]["quantity"]
[----] E, [2022-08-23T08:59:28.949873 #544:b6620] ERROR -- automation: <AEMethod getcostusage> [no implicit conversion of String into Integer]
/CloudForms_Essentials/Integration/Azure/StateMachines/getCostUsage:79:in `[]'
/CloudForms_Essentials/Integration/Azure/StateMachines/getCostUsage:79:in `<main>'
[----] I, [2022-08-23T08:59:28.974301 #544:ac260] INFO -- automation: <AEMethod [/CloudForms_Essentials/Integration/Azure/StateMachines/getCostUsage]> Ending
If I try JSON.parse(test) then I get this error.
[----] E, [2022-08-23T09:18:39.022825 #553:bcaac] ERROR -- automation: <AEMethod getcostusage> [no implicit conversion of Azure::Armrest::ArmrestCollection into String]
test is an instance of ArmrestCollection, which inherits from Array class (as can be viewed here).
To print the quantity of all elements, you can iterate it and print them each individually:
test.each do |element|
puts element["properties"]["quantity"]
end
Related
I am trying get mnesia table info from elixir shell.
I have tried to convert the string to atom.
String.to_atom("roster")
I have tried to pass string as list ["roster"]
command -
:ejabberd_admin.mnesia_table_info("roster")
error
ArgumentError
:erlang.list_to_atom("roster")
Erlang expects a charlist there, not a binary. Use single quotes:
:ejabberd_admin.mnesia_table_info('roster')
Also: Kernel.to_charlist/1, ~c/2.
Documentation on charlists on official site.
Example:
iex(1)> :erlang.list_to_atom("roster")
** (ArgumentError) argument error
:erlang.list_to_atom("roster")
iex(1)> :erlang.list_to_atom('roster')
:roster
Noticed that all the lines in Rails log (production.log for example) start with either capital "I" or capital "W". For example
I, [2017-04-04T15:40:40.409423 #15879] INFO -- : [8dd4dd50-2dba-466e-91c3-13e83333db78] Completed 302 Found in 96ms (ActiveRecord: 6.2ms)
I, [2017-04-04T15:40:40.448567 #15866] INFO -- : [e80b7bcc-92be-465a-a9b1-1f39222238cf] Started GET "/bla" for ip at 2017-04-05 15:40:40 +0200
I, [2017-04-04T15:40:40.454994 #15866] INFO -- : [e80b7bcc-92be-465a-a9b1-1f39123138cf] Processing by blaController#index as HTML
Found no explanation for why is it like this and what's the purpose.
It's the standard Logger Format with SeverityID as the first value :
Log format:
SeverityID, [DateTime #pid] SeverityLabel -- ProgName: message
Log sample:
I, [1999-03-03T02:34:24.895701 #19074] INFO -- Main: info.
I have log file in Rails 4.
Here is string.
I, [2014-09-30T19:16:23.434591 #6942] INFO -- : Completed 302 Found in 1176ms (ActiveRecord: 4.6ms)
What means number after DATETIME? #6942?
it is process id: PID
Log format: SeverityID, [DateTime #pid] SeverityLabel -- ProgName: message
Log sample: I, [1999-03-03T02:34:24.895701 #19074] INFO -- Main: info.
http://www.ruby-doc.org/stdlib-2.1.0/libdoc/logger/rdoc/Logger.html#class-Logger-label-Format
When I bind the command to key it keeps telling me "Unknown command: TestJump". Here is what I do, I run the command in console "lua_openscript_cl TestJump" then I do "Bind e "TestJump," but that is where it starts to tell me that the command is unknow, it also tells me "Something is creating script errors" when I run the command to open the script, that's also when it gives me the error below.
Error:
[ERROR] lua/testjump.lua:11: attempt to call field 'ADD' (a nil value)
1. unknown - lua/testjump.lua:11
Code:
function TestJump()
timer.simple(.7,jump) -- Jumps --
timer.simple(.7, function() RunConsoleCommand("+jump") end)
timer.simple(.72, function() RunConsoleCommand("-Jump") end)
end
-- Jumps --
function jump() -- Not sure if I'm even supposed to do this --
LocalPlayer():SetEyeAngles(LocalPlayer():EyeAngles()-Angle(0,10,0))
end
-- ^ not sure what I am supposed to do with the EyeAngle --
concommand.ADD("Test",TestJump) -- Where I think the error is --
It seems that the correct name is Add, not ADD. Lua is case-sensitive.
I want to write a table into a file which named by the date and time it created.
I can open a file with hard coded name, write the table into it, like below:
FILENAME_EVENTS="Events.txt" -- filename in string
local fp=io.open(FILENAME_EVENTS, a) -- open a new file with the file name
io.output(FILENAME_EVENTS) -- redirect the io output to the file
-- write the table into the file
for i, e in ipairs(eventlist) do io.write(e.title, e.category, e.ds, e.de, e.td) end
But when I try to:
FILENAME_EVENTS=os.date().."\.txt" -- filename in string with date
local fp=io.open(FILENAME_EVENTS, a) -- open a new file with the file name
io.output(FILENAME_EVENTS) -- redirect the io output to the file
-- write the table into the file
for i, e in ipairs(eventlist) do io.write(e.title, e.category, e.ds, e.de, e.td) end
I got an error
bad argument #1 to 'output' (10/06/11 17:45:01.txt: Invalid argument)
stack traceback:
[C]: in function 'output'
Why this "10/06/11 17:45:01.txt" is an invalid argument? due to it contains spaces or '/'? Or any other reasons?
BTW, the platform is win7 Pro + Lua 5.1.4 for win
Apparently it's both / and : that bork. The first probably because it is regarded as directory separator. This can be demonstrated as below:
fn=os.date()..'.txt'
print(io.open(fn,'w')) -- returns invalid argument
fn=os.date():gsub(':','_')..'.txt'
print(io.open(fn,'w')) -- returns nil, no such file or directory
fn=os.date():gsub('[:/]','_')..'.txt'
print(io.open(fn,'w')) -- returns file(0x...), nil <-- Works
BTW, instead of using strange gsub and concatenation tricks, you might also consider using something like
fn=os.date('%d_%m_%y %H_%M.txt')