import React, { Component } from "react"; import PropTypes from "prop-types"; import { noop } from "lodash"; import AceEditor from "react-ace"; import classnames from "classnames"; import { humanHostMemory } from "utilities/helpers"; import FleetIcon from "components/icons/FleetIcon"; import PlatformIcon from "components/icons/PlatformIcon"; import targetInterface from "interfaces/target"; const baseClass = "target-details"; class TargetDetails extends Component { static propTypes = { target: targetInterface, className: PropTypes.string, handleBackToResults: PropTypes.func, }; static defaultProps = { handleBackToResults: noop, }; onlineHosts = (labelBaseClass, count, online) => { const offline = count - online; const percentCount = ((count - offline) / count) * 100; const percentOnline = parseFloat(percentCount.toFixed(2)); if (online > 0) { return ( {" "} ({percentOnline}% ONLINE) ); } return false; }; renderHost = () => { const { className, handleBackToResults, target } = this.props; const { display_text: displayText, primary_mac: hostMac, primary_ip: hostIpAddress, memory, osquery_version: osqueryVersion, os_version: osVersion, platform, status, } = target; const hostBaseClass = "host-target"; const isOnline = status === "online"; const isOffline = status === "offline"; const statusClassName = classnames( `${hostBaseClass}__status`, { [`${hostBaseClass}__status--is-online`]: isOnline }, { [`${hostBaseClass}__status--is-offline`]: isOffline } ); return (

{displayText}

{isOnline && ( )} {isOffline && ( )} {status}

IP Address {hostIpAddress}
MAC Address {hostMac}
Platform {" "} {platform}
Operating system {osVersion}
Osquery version {osqueryVersion}
Memory {humanHostMemory(memory)}
); }; renderLabel = () => { const { onlineHosts } = this; const { handleBackToResults, className, target } = this.props; const { count, description, display_text: displayText, label_type: labelType, online, query, } = target; const labelBaseClass = "label-target"; return (

{displayText}

{count}HOSTS {onlineHosts(labelBaseClass, count, online)}

{description || "No Description"}

{labelType !== 1 && (
)}
); }; render() { const { target } = this.props; if (!target) { return false; } const { target_type: targetType } = target; const { renderHost, renderLabel } = this; if (targetType === "labels") { return renderLabel(); } return renderHost(); } } export default TargetDetails;