Skip to content

Commit

Permalink
Improvements (#65)
Browse files Browse the repository at this point in the history
* emit scan:init event, even if policy is not a string

* quiet down verbose debug logging in osquery

* Add version to app title to minimize users having to hunt the info down.

* Added minimum rescan time
  • Loading branch information
rmcvey authored Sep 21, 2018
1 parent f53de5e commit ba2a044
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ module.exports = function startServer (env, log, language, appActions, OSQuery)
version.push(v.patch)
}
v.version = semver.coerce(version.join('.'))
log.info('Version', v.version + '', 'Joined', version.join('.'), 'Coerced', semver.coerce(version.join('.')) + '')
return v
})
}
Expand Down Expand Up @@ -131,6 +130,9 @@ module.exports = function startServer (env, log, language, appActions, OSQuery)

if (typeof policy === 'string') {
policy = JSON.parse(policy)
}

if (Object.keys(policy).length) {
// show the scan is happening in the UI
io.sockets.emit('scan:init', { remote, remoteLabel })
}
Expand Down
5 changes: 3 additions & 2 deletions sources/osquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const path = require('path')
const log = require('../src/lib/logger')
const ThriftClient = require('../src/lib/ThriftClient')
const platform = os.platform()
const IS_DEV = process.env.NODE_ENV === 'development'
const { NODE_ENV, STETHOSCOPE_DEBUG } = process.env
const IS_DEV = NODE_ENV === 'development'
const OSQUERY_PID_PATH = `${app.getPath('userData')}${path.sep}.osquery.pid`

const osqueryBinaries = {
Expand All @@ -28,7 +29,7 @@ const defaultOptions = {
where: '1 = 1'
}

const debug = (...args) => log.info(`oquery: ${args.join(' ')}`)
const debug = (...args) => STETHOSCOPE_DEBUG && STETHOSCOPE_DEBUG.includes('osquery') && log.info(`oquery: ${args.join(' ')}`)

const cache = new Map()
const timers = new Map()
Expand Down
7 changes: 6 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import classNames from 'classnames'
import { HOST } from './constants'
import { MAC } from './lib/platform'
import appConfig from './config.json'
import pkg from '../package.json'
import ErrorMessage from './ErrorMessage'
import './App.css'

Expand Down Expand Up @@ -57,6 +58,7 @@ class App extends Component {
}

async componentWillMount () {
document.querySelector('title').textContent += ` (v${pkg.version})`
ipcRenderer.send('scan:init')
// perform the initial policy load & scan
await this.loadPractices()
Expand Down Expand Up @@ -138,6 +140,8 @@ class App extends Component {
showNotification
} = payload

const lastScanTime = Date.now()

// device only scan with no policy completed
if (noResults) {
return this.setState({ loading: false, scannedBy: 'Stethoscope' })
Expand All @@ -152,6 +156,7 @@ class App extends Component {

return this.setState({
loading: false,
lastScanTime,
errors: errors.map(({ message }) => message)
})
}
Expand All @@ -162,6 +167,7 @@ class App extends Component {
let newState = {
result: policy.validate,
loading: false,
lastScanTime,
remoteScan,
scannedBy
}
Expand Down Expand Up @@ -198,7 +204,6 @@ class App extends Component {

Promise.all(promises).then(([config, policy, instructions]) => {
this.setState({ config, policy, instructions }, () => {
log.info(JSON.stringify(this.state.policy))
if (!this.state.scanIsRunning) {
this.scan()
}
Expand Down
4 changes: 4 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const OFF = 'OFF'
const UNKNOWN = 'UNKNOWN'
const UNSUPPORTED = 'UNSUPPORTED'

const MINIMUM_AUTOSCAN_INTERVAL_SECONDS = 60 * 5

const PORT = 37370
const HOST = `http://127.0.0.1:${PORT}`

Expand All @@ -28,6 +30,8 @@ module.exports = {
NEVER,
IF_SUPPORTED,

MINIMUM_AUTOSCAN_INTERVAL_SECONDS,

ON,
OFF,
UNKNOWN,
Expand Down

0 comments on commit ba2a044

Please sign in to comment.