Creating a demo site for a service
Recently I wrote an app called Grafito to view systemd/journald logs (those are the logs in most Linux systems) and be able to filter them, see details of a specific entry, etc.
One problem with this kind of tool is that I can't just open it to the world because then everyone would be able to see the logs in a real machine. While that is usually not a problem because the information is not terribly useful (sure, you will know what's running, big whoops), it may display a dangerous piece of data which I may not want to expose.
So, the right way to do this is to create a demo site. It could be showing the real data from a throwaway system (like a virtual machine) or like I did show fake data.
To show fake data you can use a faker. Fakers are fun! I am using askn/faker which is a Crystal one. Fakers let you ask for, you guessed it... fake data.
For example, you can ask for an address or a credit card number and it would give you something random that matches the obvious patterns of what you ask.
One I love is to ask for say_something_smart
which gives you smart things!
Faker::Hacker.say_something_smart #=>
"Try to compress the SQL interface, maybe it will program the
back-end hard drive!"
So, I wrote a function that works like journalctl
but is totally fake. The
source code is just a quick hack.
Then, I used a conditional compile flag to route the info requests into that fake function:
{% if flag?(:fake_journal) %}
require "./fake_journal_data" # For fake data generation
{% end %}
{% if flag?(:fake_journal) %}
Log.info { "Journalctl.known_service_units: Using FAKE service units." }
fake_units = FakeJournalData::SAMPLE_UNIT_NAMES.compact.uniq.sort
Log.debug { "Returning #{fake_units.size} fake service units." }
return fake_units
{% else %}
# Return actual good stuff
{% end %}
And that's it! If I compile with -Dfake_journal
it builds a binary that is
using only fake data. Then I had it run in my home server and voilá: a demo!
See it in action! grafito-demo.ralsina.me