fleet/articles/converting-unix-timestamps-with-osquery.md

86 lines
3.1 KiB
Markdown
Raw Permalink Normal View History

Website: Migrate 6 articles from medium to fleetdm.com/articles (#5726) * website: add six product articles * images * Website: add article images * add image caption styles * Update articles/get-and-stay-compliant-across-your-devices-with-fleet.md * Update articles/get-and-stay-compliant-across-your-devices-with-fleet.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/correlate-network-connections-with-community-id-in-osquery.md * Update articles/correlate-network-connections-with-community-id-in-osquery.md * Update articles/correlate-network-connections-with-community-id-in-osquery.md * Update articles/using-elasticsearch-and-kibana-to-visualize-osquery-performance.md * Update articles/using-elasticsearch-and-kibana-to-visualize-osquery-performance.md * Update articles/using-elasticsearch-and-kibana-to-visualize-osquery-performance.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md Co-authored-by: Mike Thomas <78363703+mike-j-thomas@users.noreply.github.com>
2022-05-16 01:28:43 +00:00
# Converting unix timestamps with osquery
## Human readable timestamps
![The doctor looking at a unit timestamp in confusion](../website/assets/images/articles/converting-unix-timestamps-with-osquery-cover-800x450@2x.jpeg)
*Unix timestamps can be confusing for even the smartest Time Lord.*
If you are anything like me, and unix timestamps leave you thinking about the mysterious numbers in Lost, youre going to want to convert them into something more human friendly. Running your timestamp through any number of online converters is one way to go, but its a clunky process.
![An animated GIF of numbers changing](../website/assets/images/articles/converting-unix-timestamps-with-osquery-1-250x140@2x.gif)
*Hmm… 10800? Thats Thursday, January 1, 1970 3:00:00 AM, if Im not mistaken.*
Thankfully, we can easily convert unix timestamps directly in osquery:
```
SELECT
unixtime,
datetime(unixtime, 'unixepoch') AS timestamp
FROM
(SELECT 1623366772 AS unixtime);
unixtime = 1623366772
timestamp = 2021-06-10 23:12:52
```
The above query returns the time in UTC, but what if we want to get the local timestamp for the system being queried?
```
SELECT
datetime(unixtime, 'unixepoch') AS timestamp,
datetime(unixtime, 'unixepoch', 'localtime') AS local_timestamp FROM
(SELECT 1623366772 AS unixtime);
timestamp = 2021-06-10 23:12:52
local_timestamp = 2021-06-11 8:12:52
```
We can take this further by baking this idea into any of our queries. Lets run a simple query to get all running processes on our host.
```
SELECT
name, cmdline, start_time
FROM
processes
```
As you can see, we have `start_time` listed in unix time again.
![A screenshot of query results using UNIX timestamps](../website/assets/images/articles/converting-unix-timestamps-with-osquery-2-700x407@2x.jpeg)
So lets augment our query with the `datetime` line from before to give us a more human friendly output for `start_time`.
```
SELECT
name, cmdline,
datetime(start_time, 'unixepoch') AS start_time
FROM
processes
```
![A screenshot of query results using UTC timestamps](../website/assets/images/articles/converting-unix-timestamps-with-osquery-3-700x368@2x.jpeg)
And finally, as before, we can of course output that data as the local time for our host by you guessed it, adding `localtime` to our query.
```
SELECT
name, cmdline,
datetime(start_time, 'unixepoch', 'localtime') AS start_time
FROM
processes
```
![A screenshot of query results using localtime timestamps](../website/assets/images/articles/converting-unix-timestamps-with-osquery-4-700x368@2x.jpeg)
So there we go. Simple, human readable timestamps with osquery.
### Could this post be more helpful?
Let us know if you can think of any other example scenarios youd like us to cover.
Website: update article categories (#6679) * add deploy category, change product to guides * update links to deployment guides * Update deploy-fleet-on-hetzner-cloud.md * Update enrolling-a-digital-ocean-droplet-on-a-fleet-instance.md * Update how-to-install-osquery-and-enroll-linux-devices-into-fleet.md * Update delivering-data-to-snowflake-from-fleet-and-osquery.md * Update how-to-install-osquery-and-enroll-windows-devices-into-fleet.md * Update how-to-install-osquery-and-enroll-macos-devices-into-fleet.md * Update deploying-fleet-on-aws-with-terraform.md * Update deploying-fleet-on-render.md * Update how-to-uninstall-osquery.md * Update osquery-a-tool-to-easily-ask-questions-about-operating-systems.md * Update get-and-stay-compliant-across-your-devices-with-fleet.md * Update work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update converting-unix-timestamps-with-osquery.md * Update correlate-network-connections-with-community-id-in-osquery.md * Update using-elasticsearch-and-kibana-to-visualize-osquery-performance.md * Update fleet-quick-tips-querying-procdump-eula-has-been-accepted.md * Update locate-assets-with-osquery.md * Update osquery-consider-joining-against-the-users-table.md * Update import-and-export-queries-and-packs-in-fleet.md * Update ebpf-the-future-of-osquery-on-linux.md * Update generate-process-trees-with-osquery.md * Update get-and-stay-compliant-across-your-devices-with-fleet.md * Update work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update ebpf-the-future-of-osquery-on-linux.md * Change category meta value back to guides Co-authored-by: Desmi-Dizney <99777687+Desmi-Dizney@users.noreply.github.com> * change article category * update latest article category * add redirects for articles not handled by cloudflare rules * Update to main nav I did a little more housekeeping on the main nav for when we do the switch on these categories. - Added link to /deploy under Guides on the Documentation dropdown. - Added link to /guides under Guides on the Documentation dropdown - Removed the now redundant "See all" from under Guides on the Documentation dropdown - Removed the now redundant "See all" from under Articles on the Community dropdown (There's no need to point users to All categories any more, since all the category land are now linked to independently from the main nav. * Update article category name Co-authored-by: Desmi-Dizney <99777687+Desmi-Dizney@users.noreply.github.com> Co-authored-by: Mike Thomas <mthomas@fleetdm.com>
2022-07-21 04:59:51 +00:00
<meta name="category" value="guides">
Website: Migrate 6 articles from medium to fleetdm.com/articles (#5726) * website: add six product articles * images * Website: add article images * add image caption styles * Update articles/get-and-stay-compliant-across-your-devices-with-fleet.md * Update articles/get-and-stay-compliant-across-your-devices-with-fleet.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/apply-byod-to-soothe-supply-chain-pain.md * Update articles/correlate-network-connections-with-community-id-in-osquery.md * Update articles/correlate-network-connections-with-community-id-in-osquery.md * Update articles/correlate-network-connections-with-community-id-in-osquery.md * Update articles/using-elasticsearch-and-kibana-to-visualize-osquery-performance.md * Update articles/using-elasticsearch-and-kibana-to-visualize-osquery-performance.md * Update articles/using-elasticsearch-and-kibana-to-visualize-osquery-performance.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update articles/work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md Co-authored-by: Mike Thomas <78363703+mike-j-thomas@users.noreply.github.com>
2022-05-16 01:28:43 +00:00
<meta name="authorFullName" value="Mike Thomas">
<meta name="authorGitHubUsername" value="mike-j-thomas">
<meta name="publishedOn" value="2021-06-15">
<meta name="articleTitle" value="Converting unix timestamps with osquery">
Website: update article categories (#6679) * add deploy category, change product to guides * update links to deployment guides * Update deploy-fleet-on-hetzner-cloud.md * Update enrolling-a-digital-ocean-droplet-on-a-fleet-instance.md * Update how-to-install-osquery-and-enroll-linux-devices-into-fleet.md * Update delivering-data-to-snowflake-from-fleet-and-osquery.md * Update how-to-install-osquery-and-enroll-windows-devices-into-fleet.md * Update how-to-install-osquery-and-enroll-macos-devices-into-fleet.md * Update deploying-fleet-on-aws-with-terraform.md * Update deploying-fleet-on-render.md * Update how-to-uninstall-osquery.md * Update osquery-a-tool-to-easily-ask-questions-about-operating-systems.md * Update get-and-stay-compliant-across-your-devices-with-fleet.md * Update work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update converting-unix-timestamps-with-osquery.md * Update correlate-network-connections-with-community-id-in-osquery.md * Update using-elasticsearch-and-kibana-to-visualize-osquery-performance.md * Update fleet-quick-tips-querying-procdump-eula-has-been-accepted.md * Update locate-assets-with-osquery.md * Update osquery-consider-joining-against-the-users-table.md * Update import-and-export-queries-and-packs-in-fleet.md * Update ebpf-the-future-of-osquery-on-linux.md * Update generate-process-trees-with-osquery.md * Update get-and-stay-compliant-across-your-devices-with-fleet.md * Update work-may-be-watching-but-it-might-not-be-as-bad-as-you-think.md * Update ebpf-the-future-of-osquery-on-linux.md * Change category meta value back to guides Co-authored-by: Desmi-Dizney <99777687+Desmi-Dizney@users.noreply.github.com> * change article category * update latest article category * add redirects for articles not handled by cloudflare rules * Update to main nav I did a little more housekeeping on the main nav for when we do the switch on these categories. - Added link to /deploy under Guides on the Documentation dropdown. - Added link to /guides under Guides on the Documentation dropdown - Removed the now redundant "See all" from under Guides on the Documentation dropdown - Removed the now redundant "See all" from under Articles on the Community dropdown (There's no need to point users to All categories any more, since all the category land are now linked to independently from the main nav. * Update article category name Co-authored-by: Desmi-Dizney <99777687+Desmi-Dizney@users.noreply.github.com> Co-authored-by: Mike Thomas <mthomas@fleetdm.com>
2022-07-21 04:59:51 +00:00
<meta name="articleImageUrl" value="../website/assets/images/articles/converting-unix-timestamps-with-osquery-cover-800x450@2x.jpeg">