OutsideIT / FireMotD

:fire: Fire Framework Linux MoTD Generator :fire:
https://outsideit.net/firemotd
GNU General Public License v3.0
174 stars 45 forks source link

Json Config File #53

Closed willemdh closed 7 years ago

willemdh commented 7 years ago

As I've said a few times before, I would like to generate the information and write it to a .json document. Information that isn't necessary to load every logon, will be queried with a cronjob every X hours, which should result in faster FireMotD generation..

For this to work, there will be another package requirement, which is https://github.com/stedolan/jq

This is the best option for working with json on the commandline I think. See https://shapeshed.com/jq-json/

In CentOS it's installed with yum install jq

@ThomDietrich @dimon222 Can you guys verify if installing jq is possible on your operating systems. let me know if you see an issue with this implementation.

The config file would look more or less like this:

{
  "HostName": {
    "Generated": "@Logon",
    "Value": "$HostName",
    "LastRun": "$Date"
  },
  "HostIp": {
    "Generated": "@Logon",
    "Value": "$HostIp",
    "LastRun": "$Date"
  },
  "Release": {
    "Generated": "@Cron",
    "Value": "$Release",
    "LastRun": "$Date"
  },
  "Kernel": {
    "Generated": "@Cron",
    "Value": "$Kernel",
    "LastRun": "$Date"
  },
  "Platform": {
    "Generated": "@Cron",
    "Value": "$Platform",
    "LastRun": "$Date"
  },
  "Uptime": {
    "Generated": "@Logon",
    "Value": "$Uptime",
    "LastRun": "$Date"
  },
  "Installed": {
    "Generated": "@Never",
    "Value": "$Installed",
    "LastRun": "$Date"
  },
  "CpuUsage": {
    "Generated": "@Logon",
    "Value": "$CpuUsage",
    "LastRun": "$Date"
  },
  "CpuLoad": {
    "Generated": "@Logon",
    "Value": "$CpuLoad",
    "LastRun": "$Date"
  }
}
willemdh commented 7 years ago

@dimon222 @ThomDietrich Seems like in Ubuntu you need to compile it :(

./configure && make && sudo make install

https://stedolan.github.io/jq/download/

This is kind of annoying I guess for everyone not using yum...,?

ThomDietrich commented 7 years ago

Repository installation confirmed on Ubuntu 14.04 and Raspbian 8 (which I didn't expect). No problems on my side.

willemdh commented 7 years ago

Can you post the full installation instructions for Ubuntu? Tx

dimon222 commented 7 years ago

Debian (so should probably affect all the debian based builds) - available in official repo via sudo apt-get install jq

image

ThomDietrich commented 7 years ago

This will do

sudo apt install jq

With the focus on older systems @dimon222 's apt-get option might be safer

willemdh commented 7 years ago

@tavinus @ThomDietrich

Feel free to checkout dev-willem

Test run with sudo ./FireMotD -E

Output /var/tmp/FireJson.json:

{
  "version": {
    "Generated": "@logon",
    "Value": " 7.11.170608 ",
    "LastRun": "2017-07-11 16:19:05,835"
  },
  "hostname": {
    "Generated": "@logon",
    "Value": "n02.outsideit.net",
    "LastRun": "2017-07-11 16:19:05,835"
  },
  "hostip": {
    "Generated": "@logon",
    "Value": "172.104.134.172",
    "LastRun": "2017-07-11 16:19:05,835"
  }
}

So my plan is to build the json data file in steps. That way I can work on it when I have the time and the old method will keep working for some time.

More-utils is required too now in orde to use sponge. https://rentes.github.io/unix/utilities/2015/07/27/moreutils-package/

ThomDietrich commented 7 years ago

Sounds good and going at it step by steps is reasonable! Way to go! :tada:

willemdh commented 7 years ago

@ThomDietrich @dimon222 Ok, forget what I said, I reworked the whole thing. No backwards compatibility, as it's just too much hassle. So most functionalities have been ported. All data is written to and read from the json file /var/tmp/FireMotD.json

Could you please test it and let me know what you think. I would want to push to master asap. Only the invader and the html theme haven't been ported yet. The rest should work. it contains a default json, my goal is to make this an external file in the near future, but for now it's hardcoded.

Start with running it at least once like this:

sudo ./FireMotD -S

Then run with

./FireMotD --Theme Modern

This means we can finally use sudo commands and gather even more information. Looking forward to your opinion.

willemdh commented 7 years ago

Did another commit with some bugfixes.

willemdh commented 7 years ago

@ThomDietrich @dimon222 Ok, fixed the invader them today. Unless you guys give me a good reason not to update master with dev-willem in the next week I'm going into production.

ThomDietrich commented 7 years ago

Hey, I was a bit busy lately. The proposal and code I saw looked good and I'm sure you did a great job implementing and testing everything. I'll speak up if problems present themselves ;)

For me this will be interesting because I'll need to update the FireMotD routine in openHABian!

willemdh commented 7 years ago

Moved dev-willem to master. Closing this issue. Feel free to make new ones if you do encounter problems.