refactor!: Rename "devices" to "hosts" in "exportHistory" - operation. Prepare extraction of device specific types and alignment with integration layer
This commit is contained in:
parent
92ffe71684
commit
47640ff13e
10 changed files with 11888 additions and 35 deletions
|
|
@ -8,12 +8,11 @@ import {
|
|||
Permission,
|
||||
QueryAllHostsArgs,
|
||||
QueryAllHostGroupsArgs,
|
||||
QueryExportDeviceValueHistoryArgs,
|
||||
QueryExportUserRightsArgs,
|
||||
QueryHasPermissionsArgs,
|
||||
QueryUserPermissionsArgs,
|
||||
Resolvers,
|
||||
StorageItemType, Host,
|
||||
StorageItemType, Host, QueryExportHostValueHistoryArgs,
|
||||
} from "../generated/graphql.js";
|
||||
|
||||
import {HostImporter} from "../execution/host_importer";
|
||||
|
|
@ -92,11 +91,11 @@ export function createResolvers(): Resolvers {
|
|||
)
|
||||
},
|
||||
|
||||
exportDeviceValueHistory: (_parent: any, args: QueryExportDeviceValueHistoryArgs, {
|
||||
exportHostValueHistory: (_parent: any, args: QueryExportHostValueHistoryArgs, {
|
||||
zabbixAuthToken,
|
||||
cookie
|
||||
}: any) => {
|
||||
return HostValueExporter.exportDeviceData(args, zabbixAuthToken, cookie)
|
||||
return HostValueExporter.exportHistory(args, zabbixAuthToken, cookie)
|
||||
},
|
||||
|
||||
exportUserRights: async (_, args: QueryExportUserRightsArgs, {
|
||||
|
|
@ -134,7 +133,7 @@ export function createResolvers(): Resolvers {
|
|||
zabbixAuthToken,
|
||||
cookie
|
||||
}: any) => {
|
||||
return HostImporter.importHosts(args.devices, zabbixAuthToken, cookie)
|
||||
return HostImporter.importHosts(args.hosts, zabbixAuthToken, cookie)
|
||||
},
|
||||
importUserRights: async (_, args: MutationImportUserRightsArgs, {
|
||||
zabbixAuthToken,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import {
|
||||
ApiError,
|
||||
DeviceValueExportResponse,
|
||||
QueryExportDeviceValueHistoryArgs,
|
||||
HistoryExportResponse, QueryExportHostValueHistoryArgs,
|
||||
StorageItemType
|
||||
} from "../generated/graphql.js";
|
||||
import {ApiErrorCode, ApiErrorMessage} from "../model/model_enum_values.js";
|
||||
|
|
@ -21,7 +20,7 @@ type ItemMapResponse = {
|
|||
}
|
||||
|
||||
export class HostValueExporter {
|
||||
static async exportDeviceData(args: QueryExportDeviceValueHistoryArgs, zabbixAuthToken?: string, cookie?: string): Promise<DeviceValueExportResponse> {
|
||||
static async exportHistory(args: QueryExportHostValueHistoryArgs, zabbixAuthToken?: string, cookie?: string): Promise<HistoryExportResponse> {
|
||||
let itemMapResponse: ItemMapResponse = await HostValueExporter.queryItemsForFilterArgs(args, zabbixAuthToken, cookie);
|
||||
if (itemMapResponse.error || !itemMapResponse.items) {
|
||||
return {
|
||||
|
|
@ -74,16 +73,16 @@ export class HostValueExporter {
|
|||
}
|
||||
}
|
||||
|
||||
static async queryItemsForFilterArgs(args: QueryExportDeviceValueHistoryArgs, zabbixAuthToken?: string, cookie?: string): Promise<ItemMapResponse> {
|
||||
let deviceKeys = args.deviceKey_filter
|
||||
let attributeNames = args.attribute_filter
|
||||
static async queryItemsForFilterArgs(args: QueryExportHostValueHistoryArgs, zabbixAuthToken?: string, cookie?: string): Promise<ItemMapResponse> {
|
||||
let hostFilter = args.host_filter
|
||||
let itemKeyFilter = args.itemKey_filter
|
||||
|
||||
let items: QueryZabbixItemResponse[] | ZabbixErrorResult = await new ZabbixQueryItemsRequest(zabbixAuthToken, cookie)
|
||||
.executeRequestReturnError(zabbixAPI, new ParsedArgs(
|
||||
{
|
||||
filter: {
|
||||
host: deviceKeys,
|
||||
key_: attributeNames
|
||||
host: hostFilter,
|
||||
key_: itemKeyFilter
|
||||
},
|
||||
tags: [{"tag": "hasValue", "operator": 1, "value": "true"}]
|
||||
}))
|
||||
|
|
|
|||
|
|
@ -85,12 +85,12 @@ export class HostImporter {
|
|||
return result
|
||||
}
|
||||
|
||||
static async importHosts(devices: InputMaybe<Array<CreateHost>> | undefined, zabbixAuthToken?: string, cookie?: string) {
|
||||
if (!devices) {
|
||||
static async importHosts(hosts: InputMaybe<Array<CreateHost>> | undefined, zabbixAuthToken?: string, cookie?: string) {
|
||||
if (!hosts) {
|
||||
return null
|
||||
}
|
||||
let result: CreateHostResponse[] = []
|
||||
for (let device of devices) {
|
||||
for (let device of hosts) {
|
||||
let groupids = device.groupids
|
||||
if (!groupids) {
|
||||
groupids = await GroupHelper.findHostGroupIdsByName([ZABBIX_EDGE_DEVICE_BASE_GROUP, ...device.groupNames], zabbixAPI, zabbixAuthToken, cookie)
|
||||
|
|
|
|||
1150
src/generated/graphql.ts
Normal file
1150
src/generated/graphql.ts
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue