-
Notifications
You must be signed in to change notification settings - Fork 5
feat(mcl/host_info): Upload results to Coda #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3a5ad5d
1ab74e6
073f4d8
8ced17d
f8d82d1
bbf1503
f00425a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
monyarm marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,7 +9,7 @@ import std.stdio : writeln; | |||||
| import std.conv : to; | ||||||
| import std.string : strip, indexOf, isNumeric; | ||||||
| import std.array : split, join, array, replace; | ||||||
| import std.algorithm : map, filter, startsWith, joiner, any, sum; | ||||||
| import std.algorithm : map, filter, startsWith, joiner, any, sum, find; | ||||||
| import std.file : exists, write, readText, readLink, dirEntries, SpanMode; | ||||||
| import std.path : baseName; | ||||||
| import std.json; | ||||||
|
|
@@ -22,6 +22,7 @@ import mcl.utils.process : execute, isRoot; | |||||
| import mcl.utils.number : humanReadableSize; | ||||||
| import mcl.utils.array : uniqIfSame; | ||||||
| import mcl.utils.nix : Literal; | ||||||
| import mcl.utils.coda; | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use selective imports:
Suggested change
|
||||||
|
|
||||||
| // enum InfoFormat | ||||||
| // { | ||||||
|
|
@@ -34,10 +35,12 @@ struct Params | |||||
| { | ||||||
| // @optional() | ||||||
| // InfoFormat format = InfoFormat.JSON; | ||||||
| @optional() string codaApiToken; | ||||||
| void setup() | ||||||
| { | ||||||
| } | ||||||
| } | ||||||
| Params params; | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid global variables, as they make the control flow harder to reason about as the codebase evolves. |
||||||
|
|
||||||
| string[string] cpuinfo; | ||||||
|
|
||||||
|
|
@@ -64,7 +67,7 @@ string[string] getProcInfo(string fileOrData, bool file = true) | |||||
|
|
||||||
| export void host_info() | ||||||
| { | ||||||
| const params = parseEnv!Params; | ||||||
| params = parseEnv!Params; | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should remain a local |
||||||
|
|
||||||
| Info info = getInfo(); | ||||||
|
|
||||||
|
|
@@ -79,6 +82,8 @@ Info getInfo() | |||||
| meminfo = getProcInfo("/proc/meminfo"); | ||||||
|
|
||||||
| Info info; | ||||||
| info.softwareInfo.hostid = execute("hostid", false); | ||||||
| info.softwareInfo.hostname = execute("cat /etc/hostname", false); | ||||||
| info.softwareInfo.operatingSystemInfo = getOperatingSystemInfo(); | ||||||
| info.softwareInfo.opensshInfo = getOpenSSHInfo(); | ||||||
| info.softwareInfo.machineConfigInfo = getMachineConfigInfo(); | ||||||
|
|
@@ -90,6 +95,86 @@ Info getInfo() | |||||
| info.hardwareInfo.displayInfo = getDisplayInfo(); | ||||||
| info.hardwareInfo.graphicsProcessorInfo = getGraphicsProcessorInfo(); | ||||||
|
|
||||||
| if (params.codaApiToken) { | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inform the user of this conditional behavior by logging:
(feed free to rephrase the messages) |
||||||
| auto docId = "0rz18jyJ1M"; | ||||||
| auto hostTableId = "grid-b3MAjem325"; | ||||||
| auto cpuTableId = "grid-mCI3x3nEIE"; | ||||||
| auto memoryTableId = "grid-o7o2PeB4rz"; | ||||||
| auto motherboardTableId = "grid-270PlzmA8K"; | ||||||
| auto gpuTableId = "grid-ho6EPztvni"; | ||||||
| auto storageTableId = "grid-JvXFbttMNz"; | ||||||
| auto osTableId = "grid-ora7n98-ls"; | ||||||
monyarm marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| auto coda = CodaApiClient(params.codaApiToken); | ||||||
|
|
||||||
| auto hostValues = RowValues([ | ||||||
| CodaCell("Host Name", info.softwareInfo.hostname), | ||||||
| CodaCell("Host ID", info.softwareInfo.hostid), | ||||||
| CodaCell("OpenSSH Public Key", info.softwareInfo.opensshInfo.publicKey), | ||||||
| CodaCell("JSON", info.toJSON(true).toPrettyString(JSONOptions.doNotEscapeSlashes)) | ||||||
| ]); | ||||||
|
|
||||||
| coda.updateOrInsertRow(docId, hostTableId, hostValues); | ||||||
|
|
||||||
| auto cpuValues = RowValues([ | ||||||
| CodaCell("Host Name", info.softwareInfo.hostname), | ||||||
| CodaCell("Vendor", info.hardwareInfo.processorInfo.vendor), | ||||||
| CodaCell("Model", info.hardwareInfo.processorInfo.model), | ||||||
| CodaCell("Architecture", info.hardwareInfo.processorInfo.architectureInfo.architecture), | ||||||
| CodaCell("Flags", info.hardwareInfo.processorInfo.architectureInfo.flags), | ||||||
| ]); | ||||||
| coda.updateOrInsertRow(docId, cpuTableId, cpuValues); | ||||||
|
|
||||||
| auto memoryValues = RowValues([ | ||||||
| CodaCell("Host Name", info.softwareInfo.hostname), | ||||||
| CodaCell("Vendor", info.hardwareInfo.memoryInfo.vendor), | ||||||
| CodaCell("Part Number", info.hardwareInfo.memoryInfo.partNumber), | ||||||
| CodaCell("Serial", info.hardwareInfo.memoryInfo.serial), | ||||||
| CodaCell("Generation", info.hardwareInfo.memoryInfo.type), | ||||||
| CodaCell("Slots", info.hardwareInfo.memoryInfo.slots == 0 ? "Soldered" : info.hardwareInfo.memoryInfo.count.to!string ~ "/" ~ info.hardwareInfo.memoryInfo.slots.to!string), | ||||||
| CodaCell("Total", info.hardwareInfo.memoryInfo.total), | ||||||
| CodaCell("Speed", info.hardwareInfo.memoryInfo.speed), | ||||||
| ]); | ||||||
| coda.updateOrInsertRow(docId, memoryTableId, memoryValues); | ||||||
|
|
||||||
| auto motherboardValues = RowValues([ | ||||||
| CodaCell("Host Name", info.softwareInfo.hostname), | ||||||
| CodaCell("Vendor", info.hardwareInfo.motherboardInfo.vendor), | ||||||
| CodaCell("Model", info.hardwareInfo.motherboardInfo.model), | ||||||
| CodaCell("Revision", info.hardwareInfo.motherboardInfo.version_), | ||||||
| CodaCell("Serial", info.hardwareInfo.motherboardInfo.serial), | ||||||
| CodaCell("BIOS Vendor", info.hardwareInfo.motherboardInfo.biosInfo.vendor), | ||||||
| CodaCell("BIOS Version", info.hardwareInfo.motherboardInfo.biosInfo.version_), | ||||||
| CodaCell("BIOS Release", info.hardwareInfo.motherboardInfo.biosInfo.release), | ||||||
| CodaCell("BIOS Date", info.hardwareInfo.motherboardInfo.biosInfo.date) | ||||||
| ]); | ||||||
| coda.updateOrInsertRow(docId, motherboardTableId, motherboardValues); | ||||||
|
|
||||||
| auto gpuValues = RowValues([ | ||||||
| CodaCell("Host Name", info.softwareInfo.hostname), | ||||||
| CodaCell("Vendor", info.hardwareInfo.graphicsProcessorInfo.vendor), | ||||||
| CodaCell("Model", info.hardwareInfo.graphicsProcessorInfo.model), | ||||||
| CodaCell("VRam", info.hardwareInfo.graphicsProcessorInfo.vram) | ||||||
| ]); | ||||||
| coda.updateOrInsertRow(docId, gpuTableId, gpuValues); | ||||||
|
|
||||||
| auto osValues = RowValues([ | ||||||
| CodaCell("Host Name", info.softwareInfo.hostname), | ||||||
| CodaCell("Distribution", info.softwareInfo.operatingSystemInfo.distribution), | ||||||
| CodaCell("Distribution Version", info.softwareInfo.operatingSystemInfo.distributionVersion), | ||||||
| CodaCell("Kernel", info.softwareInfo.operatingSystemInfo.kernel), | ||||||
| CodaCell("Kernel Version", info.softwareInfo.operatingSystemInfo.kernelVersion) | ||||||
| ]); | ||||||
| coda.updateOrInsertRow(docId, osTableId, osValues); | ||||||
|
|
||||||
| auto storageValues = RowValues([ | ||||||
| CodaCell("Host Name", info.softwareInfo.hostname), | ||||||
| CodaCell("Count", info.hardwareInfo.storageInfo.devices.length.to!string), | ||||||
| CodaCell("Total", info.hardwareInfo.storageInfo.total), | ||||||
| CodaCell("JSON", info.hardwareInfo.storageInfo.toJSON(true).toPrettyString(JSONOptions.doNotEscapeSlashes)) | ||||||
| ]); | ||||||
| coda.updateOrInsertRow(docId, storageTableId, storageValues); | ||||||
| } | ||||||
|
|
||||||
| return info; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -101,6 +186,8 @@ struct Info | |||||
|
|
||||||
| struct SoftwareInfo | ||||||
| { | ||||||
| string hostname; | ||||||
| string hostid; | ||||||
| OperatingSystemInfo operatingSystemInfo; | ||||||
| OpenSSHInfo opensshInfo; | ||||||
| MachineConfigInfo machineConfigInfo; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ import std.traits : isArray; | |
| import mcl.utils.json : toJSON, fromJSON; | ||
| import std.process : environment; | ||
| import std.stdio : writeln, writefln; | ||
| import std.algorithm : map, filter; | ||
| import std.algorithm : map, filter, find; | ||
| import std.exception : assertThrown; | ||
| import std.sumtype : SumType; | ||
| import core.thread; | ||
|
|
@@ -527,6 +527,16 @@ struct CodaApiClient | |
| coda.deleteRow("dEJJPwdxcw", tables[0].id, resp[0]); | ||
| } | ||
|
|
||
| void updateOrInsertRow(string docId, string tableId, RowValues values) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the Coda Api docs, we should be able to directly create an "Upsert" request, without first fetching the data: https://coda.io/developers/apis/v1#tag/Rows/operation/upsertRows Can you look into directly doing an upsert? |
||
| auto table = listRows(docId, tableId); | ||
| auto rows = find!(row => row.name == values.cells[0].value)(table); | ||
| if (rows.length > 0) { | ||
| updateRow(docId, tableId, rows[0].id, values); | ||
| } | ||
| else { | ||
| insertRows(docId, tableId, [values]); | ||
| } | ||
PetarKirov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| struct PushButtonResponse { | ||
| string requestId; | ||
| string rowId; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -24,6 +24,7 @@ T execute(T = string)(string[] args, bool printCommand = true, bool returnErr = | |||
| import std.array : join; | ||||
| import std.algorithm : map; | ||||
| import std.conv : to; | ||||
| import std.stdio : writeln; | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this line is unused:
Suggested change
|
||||
|
|
||||
| auto cmd = args.map!escapeShellCommand.join(" "); | ||||
|
|
||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to make this attrset recursive: