Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,20 @@ module.exports = {
plugins: ['react', '@typescript-eslint'],
files: ['x-pack/plugins/osquery/**/*.{js,mjs,ts,tsx}'],
rules: {
'padding-line-between-statements': [
'error',
{
blankLine: 'always',
prev: ['block-like'],
next: ['*'],
},
{
blankLine: 'always',
prev: ['*'],
next: ['return'],
},
],
'padded-blocks': ['error', 'always'],
'arrow-body-style': ['error', 'as-needed'],
'prefer-arrow-callback': 'error',
'no-unused-vars': 'off',
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/osquery/common/ecs/ecs_fields/extend_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export const extendMap = (
): Readonly<Record<string, string>> =>
Object.entries(map).reduce<Record<string, string>>((accum, [key, value]) => {
accum[`${path}.${key}`] = `${path}.${value}`;

return accum;
}, {});
1 change: 1 addition & 0 deletions x-pack/plugins/osquery/cypress/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
module.exports = (on: any, config: any) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-extraneous-dependencies
require('@cypress/code-coverage/task')(on, config);

// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
return config;
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/osquery/cypress/tasks/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const getUrlWithRoute = (role: ROLES, route: string) => {
port: kibana.port,
} as UrlObject)}${route.startsWith('/') ? '' : '/'}${route}`;
cy.log(`origin: ${theUrl}`);

return theUrl;
};

Expand Down Expand Up @@ -92,6 +93,7 @@ export const constructUrlWithUser = (user: User, route: string) => {
const builtUrl = new URL(strUrl);

cy.log(`origin: ${builtUrl.href}`);

return builtUrl.href;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ export const AgentStatusBar: React.FC<{
}> = ({ agentStatus }) => {
const palette = useMemo(() => {
let stop = 0;

return AGENT_STATUSES.reduce((acc, status) => {
stop += agentStatus[status] || 0;
acc.push({
stop,
color: getColorForAgentStatus(status),
});

return acc;
}, [] as Array<{ stop: number; color: string }>);
}, [agentStatus]);

return (
<StyledEuiColorPaletteDisplay
className="osquery-action-agent-status-bar"
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/osquery/public/agents/agent_grouper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function genAgent(policyId: string, hostname: string, id: string): Groupe
},
};
}

export const groupData: GroupData = {
[AGENT_GROUP_KEY.Platform]: new Array(3).fill('test platform ').map((el, i) => genGroup(el + i)),
[AGENT_GROUP_KEY.Policy]: new Array(3).fill('test policy ').map((el, i) => genGroup(el + i)),
Expand Down Expand Up @@ -109,6 +110,7 @@ describe('AgentGrouper', () => {
});
};
}

it('should generate policy options', genGroupTest(AGENT_GROUP_KEY.Policy, 'policy'));
it('should generate platform options', genGroupTest(AGENT_GROUP_KEY.Platform, 'platform'));
});
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/osquery/public/agents/agent_grouper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,22 @@ export class AgentGrouper {
if (!data?.length || key === AGENT_GROUP_KEY.All) {
return;
}

const group = this.groups[key];
if (append) {
group.data.push(...data);
} else {
group.data = data;
}

group.size = data.length;
}

setTotalAgents(total: number): void {
if (total < 0) {
return;
}

this.groups[AGENT_GROUP_KEY.All].size = total;
}

Expand Down Expand Up @@ -124,6 +127,7 @@ export class AgentGrouper {
break;
}
}

return opts;
}
}
3 changes: 3 additions & 0 deletions x-pack/plugins/osquery/public/agents/agents_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const AgentsTableComponent: React.FC<AgentsTableProps> = ({ agentSelection, onCh
getNumOverlapped(selectedGroups, groups.overlap)
);
}

onChange(newAgentSelection);
setSelectedOptions(selection);
},
Expand All @@ -131,6 +132,7 @@ const AgentsTableComponent: React.FC<AgentsTableProps> = ({ agentSelection, onCh
}
}
};

if (agentSelection && !defaultValueInitialized.current && options.length) {
if (agentSelection.allAgentsSelected) {
const allAgentsOptions = find(['label', ALL_AGENTS_LABEL], options);
Expand Down Expand Up @@ -175,6 +177,7 @@ const AgentsTableComponent: React.FC<AgentsTableProps> = ({ agentSelection, onCh

const renderOption = useCallback((option, searchVal, contentClassName) => {
const { label, value } = option;

return value?.groupType === AGENT_GROUP_KEY.Agent ? (
<EuiHealth color={value?.status === 'online' ? 'success' : 'danger'}>
<span className={contentClassName}>
Expand Down
12 changes: 12 additions & 0 deletions x-pack/plugins/osquery/public/agents/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export const getNumOverlapped = (
sum += policies[pol] ?? 0;
});
});

return sum;
};

interface Aggs extends estypes.AggregationsTermsAggregateBase {
buckets: AggregationDataPoint[];
}
Expand All @@ -51,6 +53,7 @@ export const processAggregations = (aggs: Record<string, estypes.AggregationsAgg
if (platformPolicies?.buckets && policies.length > 0) {
overlap[key] = platformPolicies.buckets.reduce((acc: { [key: string]: number }, pol) => {
acc[pol.key] = pol.doc_count;

return acc;
}, {} as { [key: string]: number });
}
Expand All @@ -63,13 +66,16 @@ export const processAggregations = (aggs: Record<string, estypes.AggregationsAgg
policies,
};
};

export const generateColorPicker = () => {
const visColorsBehindText = euiPaletteColorBlindBehindText();
const typeColors = new Map<AGENT_GROUP_KEY, string>();

return (type: AGENT_GROUP_KEY) => {
if (!typeColors.has(type)) {
typeColors.set(type, visColorsBehindText[typeColors.size]);
}

return typeColors.get(type);
};
};
Expand All @@ -80,6 +86,7 @@ export const getNumAgentsInGrouping = (selectedGroups: SelectedGroups) => {
const group = selectedGroups[g];
sum += Object.keys(group).reduce((acc, k) => acc + group[k], 0);
});

return sum;
};

Expand All @@ -90,6 +97,7 @@ export const generateAgentCheck =
.map((group) => {
const selectedGroup = selectedGroups[group];
const agentGroup = groups[group];

// check if the agent platform/policy is selected
return selectedGroup[agentGroup];
})
Expand Down Expand Up @@ -124,6 +132,7 @@ export const generateAgentSelection = (selection: GroupOption[]) => {
// we don't need to calculate diffs when all agents are selected
selectedGroups.platform[key] = value.size;
}

newAgentSelection.platformsSelected.push(key);
break;
case AGENT_GROUP_KEY.Policy:
Expand All @@ -132,6 +141,7 @@ export const generateAgentSelection = (selection: GroupOption[]) => {
// we don't need to calculate diffs when all agents are selected
selectedGroups.policy[key] = value.size;
}

newAgentSelection.policiesSelected.push(key);
break;
case AGENT_GROUP_KEY.Agent:
Expand All @@ -140,6 +150,7 @@ export const generateAgentSelection = (selection: GroupOption[]) => {
// we don't need to count how many agents are selected if they are all selected
selectedAgents.push(value);
}

newAgentSelection.agents.push(key);
break;
default:
Expand All @@ -148,5 +159,6 @@ export const generateAgentSelection = (selection: GroupOption[]) => {
console.error(`unknown group type ${groupType}`);
}
}

return { newAgentSelection, selectedGroups, selectedAgents };
};
1 change: 1 addition & 0 deletions x-pack/plugins/osquery/public/agents/use_agent_details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface UseAgentDetails {
export const useAgentDetails = ({ agentId, silent, skip }: UseAgentDetails) => {
const { http } = useKibana().services;
const setErrorToast = useErrorToast();

return useQuery<GetOneAgentResponse, unknown, GetOneAgentResponse['item']>(
['agentDetails', agentId],
() => http.get(`/internal/osquery/fleet_wrapper/agents/${agentId}`),
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/osquery/public/agents/use_agent_groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const useAgentGroups = ({ osqueryPolicies, osqueryPoliciesLoading }: UseA
setPolicies(
newPolicies.map((p) => {
const name = agentPolicyById[p.id]?.name ?? p.name;

return {
...p,
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const useOsqueryPolicies = () => {
}),
}
);

return useMemo(
() => ({ osqueryPoliciesLoading, osqueryPolicies }),
[osqueryPoliciesLoading, osqueryPolicies]
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/osquery/public/common/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const generateTablePaginationOptions = (
limit: number
): PaginationInputPaginated => {
const cursorStart = activePage * limit;

return {
activePage,
cursorStart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export function useBreadcrumbs(page: Page, values: DynamicPagePathValues = {}) {
const href = breadcrumb.href
? http.basePath.prepend(`${BASE_PATH}${breadcrumb.href}`)
: undefined;

return {
...breadcrumb,
href,
Expand All @@ -171,6 +172,7 @@ export function useBreadcrumbs(page: Page, values: DynamicPagePathValues = {}) {
if (ev.metaKey || ev.altKey || ev.ctrlKey || ev.shiftKey) {
return;
}

ev.preventDefault();
application.navigateToUrl(href);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const useDiscoverLink = ({ filters }: UseDiscoverLink) => {
});
setDiscoverUrl(newUrl);
};

getDiscoverUrl();
}, [filters, locator]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ export const useErrorToast = () => {
const {
notifications: { toasts },
} = useKibana().services;

return (error?: unknown, opts?: ErrorToastOptions) => {
if (errorToast) {
toasts.remove(errorToast);
}

if (error) {
setErrorToast(
// @ts-expect-error update types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const useRouterNavigate = (
onClickCallback?: Parameters<typeof reactRouterNavigate>[2]
) => {
const history = useHistory();

return reactRouterNavigate(history, to, onClickCallback);
};

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/osquery/public/components/empty_state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const OsqueryAppEmptyStateComponent = () => {
(event) => {
if (!isModifiedEvent(event) && isLeftClickEvent(event)) {
event.preventDefault();

return navigateToApp(INTEGRATIONS_PLUGIN_ID, {
path: pagePathGetters.integration_details_overview({
pkgkey: OSQUERY_INTEGRATION_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum Section {
export const MainNavigation = () => {
const location = useLocation();
const section = useMemo(() => location.pathname.split('/')[1] ?? 'overview', [location.pathname]);

return (
<Nav>
<EuiFlexGroup gutterSize="l" alignItems="center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const ManageIntegrationLinkComponent = () => {
(event) => {
if (!isModifiedEvent(event) && isLeftClickEvent(event)) {
event.preventDefault();

return navigateToApp(INTEGRATIONS_PLUGIN_ID, {
path: pagePathGetters.integration_details_policies({
pkgkey: OSQUERY_INTEGRATION_NAME,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/osquery/public/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const OsqueryEditorComponent: React.FC<OsqueryEditorProps> = ({
]);

useEffect(() => setEditorValue(defaultValue), [defaultValue]);

return (
<EuiCodeEditor
value={editorValue}
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/osquery/public/editor/osquery_tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ type TablesJSON = Array<{
export const normalizeTables = (tablesJSON: TablesJSON) => sortBy(tablesJSON, 'name');

let osqueryTables: TablesJSON | null = null;

export const getOsqueryTables = () => {
if (!osqueryTables) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
osqueryTables = normalizeTables(require('../common/schemas/osquery/v5.2.2.json'));
}

return osqueryTables;
};

export const getOsqueryTableNames = () => flatMap(getOsqueryTables(), 'name');
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const ConfigUploaderComponent: React.FC<ConfigUploaderProps> = ({ onChange }) =>
// remove any multiple spaces from the query
return value.replaceAll(/\s(?=\s)/gm, '');
}

return value;
});

Expand Down Expand Up @@ -95,6 +96,7 @@ const ConfigUploaderComponent: React.FC<ConfigUploaderProps> = ({ onChange }) =>
);
// @ts-expect-error update types
filePickerRef.current?.removeFiles(new Event('fake'));

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const LazyOsqueryManagedCustomButtonExtension = lazy<PackageCustomExtensi
const { OsqueryManagedCustomButtonExtension } = await import(
'./osquery_managed_custom_button_extension'
);

return {
default: OsqueryManagedCustomButtonExtension,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const LazyOsqueryManagedPolicyCreateImportExtension =
const { OsqueryManagedPolicyCreateImportExtension } = await import(
'./osquery_managed_policy_create_import_extension'
);

return {
default: OsqueryManagedPolicyCreateImportExtension,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const LazyOsqueryManagedPolicyEditExtension = lazy<PackagePolicyEditExten
const { OsqueryManagedPolicyCreateImportExtension } = await import(
'./osquery_managed_policy_create_import_extension'
);

return {
default: OsqueryManagedPolicyCreateImportExtension,
};
Expand Down
Loading