1"use strict";(self.webpackChunkairpipe_docs=self.webpackChunkairpipe_docs||[]).push([[2557],{37681:(e,n,t)=>{t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>u,frontMatter:()=>a,metadata:()=>r,toc:()=>d});var s=t(74848),i=t(28453);const a={sidebar_position:2,slug:"/tutorial/parsing-with-whitespace"},o="04 - Parsing with whitespace",r={id:"tutorials/Command to API/parsing-with-whitespace",title:"04 - Parsing with whitespace",description:"The df command is a very common command used to check disk usage. It provides a table like structure of data that doesn't automatically parse.",source:"@site/docs/tutorials/Command to API/04-parsing-with-whitespace.mdx",sourceDirName:"tutorials/Command to API",slug:"/tutorial/parsing-with-whitespace",permalink:"/docs/tutorial/parsing-with-whitespace",draft:!1,unlisted:!1,editUrl:"https://github.com/AirPipeIO/airpipe-docs/tree/main/docs/tutorials/Command to API/04-parsing-with-whitespace.mdx",tags:[],version:"current",sidebarPosition:2,frontMatter:{sidebar_position:2,slug:"/tutorial/parsing-with-whitespace"},sidebar:"tutorialSidebar",previous:{title:"03 - XML output to API",permalink:"/docs/tutorial/xml-output-to-api"},next:{title:"05 - Parsing with regex",permalink:"/docs/tutorial/parsing-with-regex"}},c={},d=[{value:"Command output",id:"command-output",level:3},{value:"Review configuration",id:"review-configuration",level:3},{value:"HTTP Response",id:"http-response",level:2}];function l(e){const n={code:"code",h1:"h1",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",ul:"ul",...(0,i.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.h1,{id:"04---parsing-with-whitespace",children:"04 - Parsing with whitespace"}),"\n",(0,s.jsxs)(n.p,{children:["The ",(0,s.jsx)(n.code,{children:"df"})," command is a very common command used to check disk usage. It provides a table like structure of data that doesn't automatically parse."]}),"\n",(0,s.jsxs)(n.p,{children:["However, we can use the inbuilt parsing capabilities to handle these in more then one way, either via detecting ",(0,s.jsx)(n.code,{children:"whitespace"}),", or with ",(0,s.jsx)(n.code,{children:"regex"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["Whitespace parsing may not work for all cases where the output is as straight forward, so utilize ",(0,s.jsx)(n.code,{children:"regex"})," parsing for more complex scenarios."]}),"\n",(0,s.jsx)(n.h3,{id:"command-output",children:"Command output"}),"\n",(0,s.jsxs)(n.p,{children:["Example command output from ",(0,s.jsx)(n.code,{children:"df -k"})]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{children:"ubuntu@host:~$ df -k\nFilesystem 1K-blocks Used Available Use% Mounted on\ntmpfs 98440 1560 96880 2% /run\n/dev/sda1 47145992 5042744 42086864 11% /\ntmpfs 492196 0 492196 0% /dev/shm\ntmpfs 5120 0 5120 0% /run/lock\n/dev/sda15 99791 6418 93374 7% /boot/efi\ntmpfs 98436 4 98432 1% /run/user/1001\n"})}),"\n",(0,s.jsx)(n.h3,{id:"review-configuration",children:"Review configuration"}),"\n",(0,s.jsxs)(n.p,{children:["We have set the ",(0,s.jsx)(n.code,{children:"run"})," command to ",(0,s.jsx)(n.code,{children:"df-k"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["The parse options have explictily defined the header keys with ",(0,s.jsx)(n.code,{children:"split_whitespace"})," enabled."]}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["Place the configuration into your ",(0,s.jsx)(n.code,{children:"configs"})," directory"]}),"\n",(0,s.jsxs)(n.li,{children:["Stop/Start the binary","\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-sh",children:"./airpipe --api-key enter-your-api-key --config-dir configs/\n"})}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-yaml",metastring:'title="tutorial-df-whitespace-to-api.yml"',children:"name: tutorial-df-whitespace-to-api\n\ninterfaces:\n tutorial/parse-df-whitespace:\n output: http\n\n actions:\n - name: DiskDf\n command:\n run: df -k\n parse:\n keys: [fs, 1K-blocks, used, available, usePerc, mountedOn]\n split_whitespace: true\n"})}),"\n",(0,s.jsx)(n.h2,{id:"http-response",children:"HTTP Response"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-json",children:'{\n "data": {\n "DiskDf": {\n "data": [\n {\n "1K-blocks": 4106912,\n "available": 4105284,\n "fs": "tmpfs",\n "mountedOn": "/run",\n "usePerc": "1%",\n "used": 1628\n },\n {\n "1K-blocks": 203770680,\n "available": 5789456,\n "fs": "/dev/mapper/ubuntu--vg-ubuntu--lv",\n "mountedOn": "/",\n "usePerc": "98%",\n "used": 188632988\n },\n {\n "1K-blocks": 20534548,\n "available": 20534520,\n "fs": "tmpfs",\n "mountedOn": "/dev/shm",\n "usePerc": "1%",\n "used": 28\n },\n {\n "1K-blocks": 5120,\n "available": 5116,\n "fs": "tmpfs",\n "mountedOn": "/run/lock",\n "usePerc": "1%",\n "used": 4\n },\n {\n "1K-blocks": 1992552,\n "available": 1515172,\n "fs": "/dev/sda2",\n "mountedOn": "/boot",\n "usePerc": "20%",\n "used": 356140\n },\n {\n "1K-blocks": 4106908,\n "available": 4106832,\n "fs": "tmpfs",\n "mountedOn": "/run/user/1000",\n "usePerc": "1%",\n "used": 76\n }\n ],\n "time.ms": 20\n }\n }\n}\n'})})]})}function u(e={}){const{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(l,{...e})}):l(e)}},28453:(e,n,t)=>{t.d(n,{R:()=>o,x:()=>r});var s=t(96540);const i={},a=s.createContext(i);function o(e){const n=s.useContext(a);return s.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function r(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(i):e.components||i:o(e.components),s.createElement(a.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.