@@ -9,7 +9,7 @@ import std.stdio : writeln;
99import std.conv : to;
1010import std.string : strip, indexOf, isNumeric;
1111import std.array : split, join, array, replace;
12- import std.algorithm : map, filter, startsWith, joiner, any, sum;
12+ import std.algorithm : map, filter, startsWith, joiner, any, sum, find ;
1313import std.file : exists, write, readText, readLink, dirEntries, SpanMode;
1414import std.path : baseName;
1515import std.json ;
@@ -22,6 +22,7 @@ import mcl.utils.process : execute, isRoot;
2222import mcl.utils.number : humanReadableSize;
2323import mcl.utils.array : uniqIfSame;
2424import mcl.utils.nix : Literal;
25+ import mcl.utils.coda;
2526
2627// enum InfoFormat
2728// {
@@ -34,10 +35,12 @@ struct Params
3435{
3536 // @optional()
3637 // InfoFormat format = InfoFormat.JSON;
38+ @optional() string codaApiToken;
3739 void setup ()
3840 {
3941 }
4042}
43+ Params params;
4144
4245string [string ] cpuinfo;
4346
@@ -64,7 +67,7 @@ string[string] getProcInfo(string fileOrData, bool file = true)
6467
6568export void host_info ()
6669{
67- const params = parseEnv! Params;
70+ params = parseEnv! Params;
6871
6972 Info info = getInfo();
7073
@@ -79,6 +82,8 @@ Info getInfo()
7982 meminfo = getProcInfo(" /proc/meminfo" );
8083
8184 Info info;
85+ info.softwareInfo.hostid = execute(" hostid" , false );
86+ info.softwareInfo.hostname = execute(" cat /etc/hostname" , false );
8287 info.softwareInfo.operatingSystemInfo = getOperatingSystemInfo();
8388 info.softwareInfo.opensshInfo = getOpenSSHInfo();
8489 info.softwareInfo.machineConfigInfo = getMachineConfigInfo();
@@ -90,9 +95,91 @@ Info getInfo()
9095 info.hardwareInfo.displayInfo = getDisplayInfo();
9196 info.hardwareInfo.graphicsProcessorInfo = getGraphicsProcessorInfo();
9297
98+ if (params.codaApiToken) {
99+ auto docId = " 0rz18jyJ1M" ;
100+ auto hostTableId = " grid-b3MAjem325" ;
101+ auto cpuTableId = " grid-mCI3x3nEIE" ;
102+ auto memoryTableId = " grid-o7o2PeB4rz" ;
103+ auto motherboardTableId = " grid-270PlzmA8K" ;
104+ auto gpuTableId = " grid-ho6EPztvni" ;
105+ auto storageTableId = " grid-JvXFbttMNz" ;
106+ auto osTableId = " grid-ora7n98-ls" ;
107+ auto coda = CodaApiClient(params.codaApiToken);
108+
109+ auto hostValues = RowValues([
110+ CodaCell(" Host Name" , info.softwareInfo.hostname),
111+ CodaCell(" Host ID" , info.softwareInfo.hostid),
112+ CodaCell(" OpenSSH Public Key" , info.softwareInfo.opensshInfo.publicKey),
113+ CodaCell(" JSON" , info.toJSON(true ).toPrettyString(JSONOptions.doNotEscapeSlashes))
114+ ]);
115+
116+ coda.updateOrInsertRow(docId, hostTableId, hostValues);
117+
118+ auto cpuValues = RowValues([
119+ CodaCell(" Host Name" , info.softwareInfo.hostname),
120+ CodaCell(" Vendor" , info.hardwareInfo.processorInfo.vendor),
121+ CodaCell(" Model" , info.hardwareInfo.processorInfo.model),
122+ CodaCell(" Architecture" , info.hardwareInfo.processorInfo.architectureInfo.architecture),
123+ CodaCell(" Flags" , info.hardwareInfo.processorInfo.architectureInfo.flags),
124+ ]);
125+ coda.updateOrInsertRow(docId, cpuTableId, cpuValues);
126+
127+ auto memoryValues = RowValues([
128+ CodaCell(" Host Name" , info.softwareInfo.hostname),
129+ CodaCell(" Vendor" , info.hardwareInfo.memoryInfo.vendor),
130+ CodaCell(" Part Number" , info.hardwareInfo.memoryInfo.partNumber),
131+ CodaCell(" Serial" , info.hardwareInfo.memoryInfo.serial),
132+ CodaCell(" Generation" , info.hardwareInfo.memoryInfo.type),
133+ CodaCell(" Slots" , info.hardwareInfo.memoryInfo.slots == 0 ? " Soldered" : info.hardwareInfo.memoryInfo.count.to! string ~ " /" ~ info.hardwareInfo.memoryInfo.slots.to! string ),
134+ CodaCell(" Total" , info.hardwareInfo.memoryInfo.total),
135+ CodaCell(" Speed" , info.hardwareInfo.memoryInfo.speed),
136+ ]);
137+ coda.updateOrInsertRow(docId, memoryTableId, memoryValues);
138+
139+ auto motherboardValues = RowValues([
140+ CodaCell(" Host Name" , info.softwareInfo.hostname),
141+ CodaCell(" Vendor" , info.hardwareInfo.motherboardInfo.vendor),
142+ CodaCell(" Model" , info.hardwareInfo.motherboardInfo.model),
143+ CodaCell(" Revision" , info.hardwareInfo.motherboardInfo.version_),
144+ CodaCell(" Serial" , info.hardwareInfo.motherboardInfo.serial),
145+ CodaCell(" BIOS Vendor" , info.hardwareInfo.motherboardInfo.biosInfo.vendor),
146+ CodaCell(" BIOS Version" , info.hardwareInfo.motherboardInfo.biosInfo.version_),
147+ CodaCell(" BIOS Release" , info.hardwareInfo.motherboardInfo.biosInfo.release),
148+ CodaCell(" BIOS Date" , info.hardwareInfo.motherboardInfo.biosInfo.date)
149+ ]);
150+ coda.updateOrInsertRow(docId, motherboardTableId, motherboardValues);
151+
152+ auto gpuValues = RowValues([
153+ CodaCell(" Host Name" , info.softwareInfo.hostname),
154+ CodaCell(" Vendor" , info.hardwareInfo.graphicsProcessorInfo.vendor),
155+ CodaCell(" Model" , info.hardwareInfo.graphicsProcessorInfo.model),
156+ CodaCell(" VRam" , info.hardwareInfo.graphicsProcessorInfo.vram)
157+ ]);
158+ coda.updateOrInsertRow(docId, gpuTableId, gpuValues);
159+
160+ auto osValues = RowValues([
161+ CodaCell(" Host Name" , info.softwareInfo.hostname),
162+ CodaCell(" Distribution" , info.softwareInfo.operatingSystemInfo.distribution),
163+ CodaCell(" Distribution Version" , info.softwareInfo.operatingSystemInfo.distributionVersion),
164+ CodaCell(" Kernel" , info.softwareInfo.operatingSystemInfo.kernel),
165+ CodaCell(" Kernel Version" , info.softwareInfo.operatingSystemInfo.kernelVersion)
166+ ]);
167+ coda.updateOrInsertRow(docId, osTableId, osValues);
168+
169+ auto storageValues = RowValues([
170+ CodaCell(" Host Name" , info.softwareInfo.hostname),
171+ CodaCell(" Count" , info.hardwareInfo.storageInfo.devices.length.to! string ),
172+ CodaCell(" Total" , info.hardwareInfo.storageInfo.total),
173+ CodaCell(" JSON" , info.hardwareInfo.storageInfo.toJSON(true ).toPrettyString(JSONOptions.doNotEscapeSlashes))
174+ ]);
175+ coda.updateOrInsertRow(docId, storageTableId, storageValues);
176+ }
177+
93178 return info;
94179}
95180
181+
182+
96183struct Info
97184{
98185 SoftwareInfo softwareInfo;
@@ -101,6 +188,8 @@ struct Info
101188
102189struct SoftwareInfo
103190{
191+ string hostname;
192+ string hostid;
104193 OperatingSystemInfo operatingSystemInfo;
105194 OpenSSHInfo opensshInfo;
106195 MachineConfigInfo machineConfigInfo;
@@ -308,7 +397,7 @@ string getDistribution()
308397 if (exists(" /etc/os-release" ))
309398 {
310399 foreach (line; execute([
311- " awk" , " -F" , " =" , " /^NAME=/ {print $2}" , " /etc/os-release"
400+ " awk" , " -F" , " =" , " ' /^NAME=/ {print $2}' " , " /etc/os-release"
312401 ], false ).split(" \n " ))
313402 {
314403 distribution = line;
@@ -331,7 +420,7 @@ string getDistributionVersion()
331420 if (exists(" /etc/os-release" ))
332421 {
333422 foreach (line; execute([
334- " awk" , " -F" , " =" , " /^VERSION=/ {print $2}" , " /etc/os-release"
423+ " awk" , " -F" , " =" , " ' /^VERSION=/ {print $2}' " , " /etc/os-release"
335424 ], false ).split(" \n " ))
336425 {
337426 distributionVersion = line.strip(" \" " );
0 commit comments