Skip to content

Commit f270f6e

Browse files
luancazarinecoderabbitai[bot]michelle0927
authored
New Components - ninjaone (#16755)
* ninjaone init * [Components] ninjaone #14845 Sources - New Device Online (Instant) Actions - Create Ticket - Update Device * pnpm update * pnpm update * pnpm update * Update components/ninjaone/ninjaone.app.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * some adjusts * Update components/ninjaone/sources/new-device-online/new-device-online.mjs Co-authored-by: michelle0927 <[email protected]> * Update components/ninjaone/ninjaone.app.mjs Co-authored-by: michelle0927 <[email protected]> * Update components/ninjaone/ninjaone.app.mjs Co-authored-by: michelle0927 <[email protected]> * Update components/ninjaone/ninjaone.app.mjs Co-authored-by: michelle0927 <[email protected]> * Update components/ninjaone/ninjaone.app.mjs Co-authored-by: michelle0927 <[email protected]> * Update components/ninjaone/ninjaone.app.mjs Co-authored-by: michelle0927 <[email protected]> * Update components/ninjaone/actions/update-device/update-device.mjs Co-authored-by: michelle0927 <[email protected]> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: michelle0927 <[email protected]>
1 parent 6ab6cae commit f270f6e

File tree

10 files changed

+752
-14
lines changed

10 files changed

+752
-14
lines changed
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import {
3+
PRIORITY_OPTIONS,
4+
SEVERITY_OPTIONS,
5+
TYPE_OPTIONS,
6+
} from "../../common/constants.mjs";
7+
import {
8+
normalCase,
9+
parseObject,
10+
} from "../../common/utils.mjs";
11+
import ninjaone from "../../ninjaone.app.mjs";
12+
13+
export default {
14+
key: "ninjaone-create-ticket",
15+
name: "Create Support Ticket",
16+
description: "Creates a new support ticket in NinjaOne. [See the documentation](https://app.ninjarmm.com/apidocs/?links.active=core#/ticketing/create)",
17+
version: "0.0.1",
18+
type: "action",
19+
props: {
20+
ninjaone,
21+
clientId: {
22+
propDefinition: [
23+
ninjaone,
24+
"clientId",
25+
],
26+
},
27+
ticketFormId: {
28+
propDefinition: [
29+
ninjaone,
30+
"ticketFormId",
31+
],
32+
},
33+
organizationId: {
34+
propDefinition: [
35+
ninjaone,
36+
"organizationId",
37+
],
38+
optional: true,
39+
},
40+
locationId: {
41+
propDefinition: [
42+
ninjaone,
43+
"locationId",
44+
({ organizationId }) => ({
45+
organizationId,
46+
}),
47+
],
48+
optional: true,
49+
},
50+
nodeId: {
51+
propDefinition: [
52+
ninjaone,
53+
"deviceId",
54+
({ organizationId }) => ({
55+
organizationId,
56+
}),
57+
],
58+
optional: true,
59+
},
60+
subject: {
61+
type: "string",
62+
label: "Subject",
63+
description: "The subject of the ticket",
64+
},
65+
descriptionPublic: {
66+
type: "boolean",
67+
label: "Public Description",
68+
description: "Whether the ticket's description is public or not",
69+
},
70+
descriptionBody: {
71+
type: "string",
72+
label: "Description Body",
73+
description: "The description of the ticket",
74+
optional: true,
75+
},
76+
descriptionHTML: {
77+
type: "string",
78+
label: "Description HTML",
79+
description: "The description HTML of the ticket",
80+
optional: true,
81+
},
82+
descriptiontimeTracked: {
83+
type: "integer",
84+
label: "Time Tracked",
85+
description: "Time in seconds",
86+
optional: true,
87+
},
88+
descriptionDuplicateInIncidents: {
89+
type: "boolean",
90+
label: "Duplicate In Incidents",
91+
description: "Whether the ticket will duplicate in the same incident",
92+
optional: true,
93+
},
94+
status: {
95+
propDefinition: [
96+
ninjaone,
97+
"status",
98+
],
99+
},
100+
type: {
101+
type: "string",
102+
label: "Type",
103+
description: "The type of the ticket",
104+
options: TYPE_OPTIONS,
105+
optional: true,
106+
},
107+
cc: {
108+
type: "string[]",
109+
label: "CC",
110+
description: "A list of emails to be copied in the notification email",
111+
optional: true,
112+
},
113+
assignedAppUserId: {
114+
propDefinition: [
115+
ninjaone,
116+
"assignedAppUserId",
117+
],
118+
optional: true,
119+
},
120+
severity: {
121+
type: "string",
122+
label: "Severity",
123+
description: "The severity's level of the ticket",
124+
options: SEVERITY_OPTIONS,
125+
optional: true,
126+
},
127+
priority: {
128+
type: "string",
129+
label: "Priority",
130+
description: "The priority's level of the ticket",
131+
options: PRIORITY_OPTIONS,
132+
optional: true,
133+
},
134+
tags: {
135+
propDefinition: [
136+
ninjaone,
137+
"tags",
138+
],
139+
optional: true,
140+
},
141+
},
142+
async run({ $ }) {
143+
try {
144+
const {
145+
ninjaone,
146+
descriptionPublic,
147+
descriptionBody,
148+
descriptionHTML,
149+
descriptiontimeTracked,
150+
descriptionDuplicateInIncidents,
151+
cc,
152+
tags,
153+
...data
154+
} = this;
155+
156+
const response = await ninjaone.createSupportTicket({
157+
$,
158+
data: {
159+
...data,
160+
description: {
161+
public: descriptionPublic,
162+
body: descriptionBody,
163+
htmlBody: descriptionHTML,
164+
timeTracked: descriptiontimeTracked,
165+
duplicateInIncidents: descriptionDuplicateInIncidents,
166+
},
167+
cc: {
168+
emails: parseObject(cc),
169+
},
170+
tags: parseObject(tags),
171+
},
172+
});
173+
174+
$.export("$summary", `Ticket created successfully with ID: ${response.id}`);
175+
return response;
176+
} catch ({ response }) {
177+
throw new ConfigurationError(normalCase(response.data.resultCode) || response.data);
178+
}
179+
},
180+
};
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import ninjaone from "../../ninjaone.app.mjs";
2+
3+
export default {
4+
key: "ninjaone-update-device",
5+
name: "Update Device",
6+
description: "Update details for a specific device in NinjaOne. [See the documentation](https://app.ninjarmm.com/apidocs/?links.active=core)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
ninjaone,
11+
deviceId: {
12+
propDefinition: [
13+
ninjaone,
14+
"deviceId",
15+
],
16+
description: "The ID of the device to update ",
17+
},
18+
displayName: {
19+
type: "string",
20+
label: "Display Name",
21+
description: "The name of the device",
22+
optional: true,
23+
},
24+
nodeRoleId: {
25+
propDefinition: [
26+
ninjaone,
27+
"nodeRoleId",
28+
],
29+
optional: true,
30+
},
31+
policyId: {
32+
propDefinition: [
33+
ninjaone,
34+
"policyId",
35+
],
36+
optional: true,
37+
},
38+
organizationId: {
39+
propDefinition: [
40+
ninjaone,
41+
"organizationId",
42+
],
43+
optional: true,
44+
},
45+
locationId: {
46+
propDefinition: [
47+
ninjaone,
48+
"locationId",
49+
({ organizationId }) => ({
50+
organizationId,
51+
}),
52+
],
53+
optional: true,
54+
},
55+
},
56+
async run({ $ }) {
57+
const {
58+
ninjaone,
59+
deviceId,
60+
...data
61+
} = this;
62+
63+
const response = await ninjaone.updateDevice({
64+
$,
65+
deviceId,
66+
data,
67+
});
68+
69+
$.export("$summary", `Successfully updated device with ID ${deviceId}`);
70+
return response;
71+
},
72+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export const LIMIT = 100;
2+
3+
export const TYPE_OPTIONS = [
4+
"PROBLEM",
5+
"QUESTION",
6+
"INCIDENT",
7+
"TASK",
8+
];
9+
10+
export const SEVERITY_OPTIONS = [
11+
"NONE",
12+
"MINOR",
13+
"MODERATE",
14+
"MAJOR",
15+
"CRITICAL",
16+
];
17+
18+
export const PRIORITY_OPTIONS = [
19+
"NONE",
20+
"LOW",
21+
"MEDIUM",
22+
"HIGH",
23+
];

components/ninjaone/common/utils.mjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};
25+
26+
export const normalCase = (s) =>
27+
s?.replace (/^[-_]*(.)/, (_, c) => c.toUpperCase())
28+
.replace (/[-_]+(.)/g, (_, c) => " " + c);

0 commit comments

Comments
 (0)