@oneuptime/common 14.0.95 → 14.0.97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/Models/AnalyticsModels/NetworkFlow.d.mts +4 -0
  2. package/Models/AnalyticsModels/NetworkFlow.d.ts +4 -0
  3. package/Models/AnalyticsModels/NetworkFlow.js +50 -0
  4. package/Models/DatabaseModels/Alert.d.mts +2 -0
  5. package/Models/DatabaseModels/Alert.d.ts +2 -0
  6. package/Models/DatabaseModels/Alert.js +63 -0
  7. package/Models/DatabaseModels/DatabaseBaseModel/DatabaseBaseModel.js +14 -37
  8. package/Models/DatabaseModels/DetectionRuleException.d.mts +25 -0
  9. package/Models/DatabaseModels/DetectionRuleException.d.ts +25 -0
  10. package/Models/DatabaseModels/DetectionRuleException.js +412 -0
  11. package/Models/DatabaseModels/DetectionRuleException.mjs +2 -0
  12. package/Models/DatabaseModels/Incident.d.mts +2 -0
  13. package/Models/DatabaseModels/Incident.d.ts +2 -0
  14. package/Models/DatabaseModels/Incident.js +63 -0
  15. package/Models/DatabaseModels/Index.js +12 -0
  16. package/Models/DatabaseModels/NetworkAddressName.d.mts +14 -0
  17. package/Models/DatabaseModels/NetworkAddressName.d.ts +14 -0
  18. package/Models/DatabaseModels/NetworkAddressName.js +300 -0
  19. package/Models/DatabaseModels/NetworkAddressName.mjs +2 -0
  20. package/Models/DatabaseModels/NetworkDevice.d.mts +1 -0
  21. package/Models/DatabaseModels/NetworkDevice.d.ts +1 -0
  22. package/Models/DatabaseModels/NetworkDevice.js +38 -0
  23. package/Models/DatabaseModels/SecurityCase.d.mts +8 -0
  24. package/Models/DatabaseModels/SecurityCase.d.ts +8 -0
  25. package/Models/DatabaseModels/SecurityCase.js +145 -0
  26. package/Models/DatabaseModels/SecurityCaseEvidence.d.mts +28 -0
  27. package/Models/DatabaseModels/SecurityCaseEvidence.d.ts +28 -0
  28. package/Models/DatabaseModels/SecurityCaseEvidence.js +489 -0
  29. package/Models/DatabaseModels/SecurityCaseEvidence.mjs +2 -0
  30. package/Models/DatabaseModels/SecurityCaseFeed.d.mts +4 -1
  31. package/Models/DatabaseModels/SecurityCaseFeed.d.ts +4 -1
  32. package/Models/DatabaseModels/SecurityCaseFeed.js +6 -0
  33. package/Models/DatabaseModels/SecurityCasePriority.d.mts +2 -0
  34. package/Models/DatabaseModels/SecurityCasePriority.d.ts +2 -0
  35. package/Models/DatabaseModels/SecurityCasePriority.js +44 -0
  36. package/Models/DatabaseModels/SecurityCaseTask.d.mts +22 -0
  37. package/Models/DatabaseModels/SecurityCaseTask.d.ts +22 -0
  38. package/Models/DatabaseModels/SecurityCaseTask.js +467 -0
  39. package/Models/DatabaseModels/SecurityCaseTask.mjs +2 -0
  40. package/Models/DatabaseModels/SecurityWatchlist.d.mts +22 -0
  41. package/Models/DatabaseModels/SecurityWatchlist.d.ts +22 -0
  42. package/Models/DatabaseModels/SecurityWatchlist.js +411 -0
  43. package/Models/DatabaseModels/SecurityWatchlist.mjs +2 -0
  44. package/Models/DatabaseModels/SecurityWatchlistItem.d.mts +17 -0
  45. package/Models/DatabaseModels/SecurityWatchlistItem.d.ts +17 -0
  46. package/Models/DatabaseModels/SecurityWatchlistItem.js +321 -0
  47. package/Models/DatabaseModels/SecurityWatchlistItem.mjs +2 -0
  48. package/Types/AI/AiAffectedResources.d.mts +2 -1
  49. package/Types/AI/AiAffectedResources.d.ts +2 -1
  50. package/Types/AI/AiAffectedResources.js +12 -1
  51. package/Types/AffectedResources/AffectedResourceSearch.d.mts +53 -0
  52. package/Types/AffectedResources/AffectedResourceSearch.d.ts +53 -0
  53. package/Types/AffectedResources/AffectedResourceSearch.js +224 -0
  54. package/Types/AffectedResources/AffectedResourceSearch.mjs +11 -0
  55. package/Types/ArchivableValue/ArchivableValueUsage.d.mts +21 -2
  56. package/Types/ArchivableValue/ArchivableValueUsage.d.ts +21 -2
  57. package/Types/ArchivableValue/ArchivableValueUsage.js +91 -12
  58. package/Types/ArchivableValue/ArchivableValueUsage.mjs +1 -0
  59. package/Types/Color.d.mts +0 -2
  60. package/Types/Color.d.ts +0 -2
  61. package/Types/Color.js +0 -14
  62. package/Types/Database/DatabaseProperty.d.mts +0 -2
  63. package/Types/Database/DatabaseProperty.d.ts +0 -2
  64. package/Types/Database/DatabaseProperty.js +0 -3
  65. package/Types/Database/TableColumn.d.mts +8 -0
  66. package/Types/Database/TableColumn.d.ts +8 -0
  67. package/Types/Database/TableColumn.js +69 -23
  68. package/Types/Database/TableColumn.mjs +1 -0
  69. package/Types/Date.d.mts +0 -2
  70. package/Types/Date.d.ts +0 -2
  71. package/Types/Date.js +0 -23
  72. package/Types/Domain.d.mts +0 -2
  73. package/Types/Domain.d.ts +0 -2
  74. package/Types/Domain.js +0 -14
  75. package/Types/Email/EmailTemplateType.d.mts +2 -0
  76. package/Types/Email/EmailTemplateType.d.ts +2 -0
  77. package/Types/Email/EmailTemplateType.js +2 -0
  78. package/Types/Email.d.mts +0 -2
  79. package/Types/Email.d.ts +0 -2
  80. package/Types/Email.js +0 -15
  81. package/Types/IP/IP.d.mts +0 -2
  82. package/Types/IP/IP.d.ts +0 -2
  83. package/Types/IP/IP.js +0 -14
  84. package/Types/JSONFunctions.js +16 -1
  85. package/Types/Monitor/CriteriaAlert.d.mts +0 -2
  86. package/Types/Monitor/CriteriaAlert.d.ts +0 -2
  87. package/Types/Monitor/CriteriaAlert.js +0 -18
  88. package/Types/Monitor/CriteriaAlert.mjs +1 -2
  89. package/Types/Monitor/CriteriaFilter.d.mts +0 -2
  90. package/Types/Monitor/CriteriaFilter.d.ts +0 -2
  91. package/Types/Monitor/CriteriaFilter.js +1 -42
  92. package/Types/Monitor/CriteriaFilter.mjs +0 -1
  93. package/Types/Monitor/CriteriaIncident.d.mts +0 -2
  94. package/Types/Monitor/CriteriaIncident.d.ts +0 -2
  95. package/Types/Monitor/CriteriaIncident.js +0 -23
  96. package/Types/Monitor/CriteriaIncident.mjs +1 -2
  97. package/Types/Monitor/IncomingMonitor/IncidentGroupingConfig.d.mts +0 -2
  98. package/Types/Monitor/IncomingMonitor/IncidentGroupingConfig.d.ts +0 -2
  99. package/Types/Monitor/IncomingMonitor/IncidentGroupingConfig.js +0 -11
  100. package/Types/Monitor/IncomingMonitor/IncidentGroupingConfig.mjs +1 -2
  101. package/Types/Monitor/MonitorCriteria.d.mts +0 -2
  102. package/Types/Monitor/MonitorCriteria.d.ts +0 -2
  103. package/Types/Monitor/MonitorCriteria.js +0 -21
  104. package/Types/Monitor/MonitorCriteriaInstance.d.mts +0 -2
  105. package/Types/Monitor/MonitorCriteriaInstance.d.ts +0 -2
  106. package/Types/Monitor/MonitorCriteriaInstance.js +0 -54
  107. package/Types/Monitor/MonitorStep.d.mts +0 -2
  108. package/Types/Monitor/MonitorStep.d.ts +0 -2
  109. package/Types/Monitor/MonitorStep.js +0 -80
  110. package/Types/Monitor/MonitorSteps.d.mts +0 -2
  111. package/Types/Monitor/MonitorSteps.d.ts +0 -2
  112. package/Types/Monitor/MonitorSteps.js +0 -31
  113. package/Types/Monitor/MonitorType.js +5 -4
  114. package/Types/Monitor/TelemetryAlertRule.d.mts +111 -0
  115. package/Types/Monitor/TelemetryAlertRule.d.ts +111 -0
  116. package/Types/Monitor/TelemetryAlertRule.js +886 -0
  117. package/Types/Monitor/TelemetryAlertRule.mjs +5 -0
  118. package/Types/Monitor/TelemetryRulePreview.d.mts +57 -0
  119. package/Types/Monitor/TelemetryRulePreview.d.ts +57 -0
  120. package/Types/Monitor/TelemetryRulePreview.js +190 -0
  121. package/Types/Monitor/TelemetryRulePreview.mjs +6 -0
  122. package/Types/Name.d.mts +0 -2
  123. package/Types/Name.d.ts +0 -2
  124. package/Types/Name.js +0 -14
  125. package/Types/NetFlow/NetworkAddressName.d.mts +30 -0
  126. package/Types/NetFlow/NetworkAddressName.d.ts +30 -0
  127. package/Types/NetFlow/NetworkAddressName.js +149 -0
  128. package/Types/NetFlow/NetworkAddressName.mjs +6 -0
  129. package/Types/NetFlow/NetworkTraffic.d.mts +20 -0
  130. package/Types/NetFlow/NetworkTraffic.d.ts +20 -0
  131. package/Types/NetFlow/NetworkTraffic.js +5 -1
  132. package/Types/NetFlow/NetworkTraffic.mjs +2 -0
  133. package/Types/NetworkController/NetworkControllerReadSummary.d.mts +2 -0
  134. package/Types/NetworkController/NetworkControllerReadSummary.d.ts +2 -0
  135. package/Types/NetworkController/NetworkControllerReadSummary.js +7 -1
  136. package/Types/NetworkDevice/NetworkDeviceDiscoveredDetails.d.mts +47 -1
  137. package/Types/NetworkDevice/NetworkDeviceDiscoveredDetails.d.ts +47 -1
  138. package/Types/NetworkDevice/NetworkDeviceDiscoveredDetails.js +173 -8
  139. package/Types/NetworkDevice/NetworkDeviceDiscoveredDetails.mjs +7 -0
  140. package/Types/NotificationSetting/NotificationEmailRollupCategory.js +3 -0
  141. package/Types/NotificationSetting/NotificationEmailRollupPolicy.js +6 -0
  142. package/Types/NotificationSetting/NotificationSettingEventType.d.mts +2 -0
  143. package/Types/NotificationSetting/NotificationSettingEventType.d.ts +2 -0
  144. package/Types/NotificationSetting/NotificationSettingEventType.js +9 -0
  145. package/Types/ObjectID.d.mts +0 -1
  146. package/Types/ObjectID.d.ts +0 -1
  147. package/Types/ObjectID.js +0 -9
  148. package/Types/OnCallDutyPolicy/EveryNewEventRules.d.mts +23 -0
  149. package/Types/OnCallDutyPolicy/EveryNewEventRules.d.ts +23 -0
  150. package/Types/OnCallDutyPolicy/EveryNewEventRules.js +105 -0
  151. package/Types/OnCallDutyPolicy/EveryNewEventRules.mjs +9 -0
  152. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunEnding.d.mts +4 -0
  153. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunEnding.d.ts +4 -0
  154. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunEnding.js +25 -1
  155. package/Types/OnCallDutyPolicy/OnCallDutyPolicyRunEnding.mjs +4 -0
  156. package/Types/OnCallDutyPolicy/OnCallEmptyLevel.d.mts +15 -0
  157. package/Types/OnCallDutyPolicy/OnCallEmptyLevel.d.ts +15 -0
  158. package/Types/OnCallDutyPolicy/OnCallEmptyLevel.js +118 -0
  159. package/Types/OnCallDutyPolicy/OnCallEmptyLevel.mjs +9 -0
  160. package/Types/Permission.d.mts +8 -0
  161. package/Types/Permission.d.ts +8 -0
  162. package/Types/Permission.js +87 -3
  163. package/Types/Phone.d.mts +0 -2
  164. package/Types/Phone.d.ts +0 -2
  165. package/Types/Phone.js +0 -14
  166. package/Types/Port.d.mts +0 -2
  167. package/Types/Port.d.ts +0 -2
  168. package/Types/Port.js +0 -14
  169. package/Types/ProviderLogo/ProviderLogo.d.mts +24 -1
  170. package/Types/ProviderLogo/ProviderLogo.d.ts +24 -1
  171. package/Types/ProviderLogo/ProviderLogo.js +47 -0
  172. package/Types/SecurityCase/SecurityCaseEvidenceKind.d.mts +7 -0
  173. package/Types/SecurityCase/SecurityCaseEvidenceKind.d.ts +7 -0
  174. package/Types/SecurityCase/SecurityCaseEvidenceKind.js +24 -0
  175. package/Types/SecurityCase/SecurityCaseEvidenceKind.mjs +4 -0
  176. package/Types/SecurityEvent/DetectionRetrohunt.d.mts +38 -0
  177. package/Types/SecurityEvent/DetectionRetrohunt.d.ts +38 -0
  178. package/Types/SecurityEvent/DetectionRetrohunt.js +147 -0
  179. package/Types/SecurityEvent/DetectionRetrohunt.mjs +10 -0
  180. package/Types/SecurityEvent/DetectionRuleException.d.mts +65 -0
  181. package/Types/SecurityEvent/DetectionRuleException.d.ts +65 -0
  182. package/Types/SecurityEvent/DetectionRuleException.js +441 -0
  183. package/Types/SecurityEvent/DetectionRuleException.mjs +24 -0
  184. package/Types/SecurityEvent/SecurityWatchlist.d.mts +167 -0
  185. package/Types/SecurityEvent/SecurityWatchlist.d.ts +167 -0
  186. package/Types/SecurityEvent/SecurityWatchlist.js +648 -0
  187. package/Types/SecurityEvent/SecurityWatchlist.mjs +51 -0
  188. package/Types/SecurityEvent/SigmaRule.d.mts +2 -0
  189. package/Types/SecurityEvent/SigmaRule.d.ts +2 -0
  190. package/Types/SecurityEvent/SigmaRule.js +5 -0
  191. package/Types/Telemetry/OpenTelemetryGuides.d.mts +52 -0
  192. package/Types/Telemetry/OpenTelemetryGuides.d.ts +52 -0
  193. package/Types/Telemetry/OpenTelemetryGuides.js +591 -0
  194. package/Types/Telemetry/OpenTelemetryGuides.mjs +17 -0
  195. package/Types/Version.d.mts +0 -2
  196. package/Types/Version.d.ts +0 -2
  197. package/Types/Version.js +0 -14
  198. package/Types/Workflow/AffectedResourcesSetting.d.mts +13 -0
  199. package/Types/Workflow/AffectedResourcesSetting.d.ts +13 -0
  200. package/Types/Workflow/AffectedResourcesSetting.js +120 -0
  201. package/Types/Workflow/AffectedResourcesSetting.mjs +8 -0
  202. package/Types/Workflow/Components/BaseModel.js +15 -3
  203. package/Types/Workflow/Documentation/DatabaseDocumentation.js +36 -0
  204. package/Utils/Inventory/AssetFactSource.d.mts +6 -2
  205. package/Utils/Inventory/AssetFactSource.d.ts +6 -2
  206. package/Utils/Inventory/AssetFactSource.js +18 -1
  207. package/Utils/Inventory/AssetFactSource.mjs +1 -0
  208. package/Utils/Markdown/FeedLead.d.mts +10 -0
  209. package/Utils/Markdown/FeedLead.d.ts +10 -0
  210. package/Utils/Markdown/FeedLead.js +198 -0
  211. package/Utils/Markdown/FeedLead.mjs +8 -0
  212. package/Utils/NetworkDevice/NetworkDeviceAssetFacts.d.mts +9 -1
  213. package/Utils/NetworkDevice/NetworkDeviceAssetFacts.d.ts +9 -1
  214. package/Utils/NetworkDevice/NetworkDeviceAssetFacts.js +139 -18
  215. package/Utils/NetworkDevice/NetworkDeviceAssetFacts.mjs +1 -0
  216. package/Utils/NetworkDevice/NetworkDeviceRefresh.d.mts +88 -0
  217. package/Utils/NetworkDevice/NetworkDeviceRefresh.d.ts +88 -0
  218. package/Utils/NetworkDevice/NetworkDeviceRefresh.js +232 -0
  219. package/Utils/NetworkDevice/NetworkDeviceRefresh.mjs +16 -0
  220. package/Utils/NetworkTraffic/NetworkAddressBlock.d.mts +20 -0
  221. package/Utils/NetworkTraffic/NetworkAddressBlock.d.ts +20 -0
  222. package/Utils/NetworkTraffic/NetworkAddressBlock.js +264 -0
  223. package/Utils/NetworkTraffic/NetworkAddressBlock.mjs +3 -0
  224. package/Utils/Schema/MonitorSchemas.d.mts +9 -0
  225. package/Utils/Schema/MonitorSchemas.d.ts +9 -0
  226. package/Utils/Schema/MonitorSchemas.js +291 -0
  227. package/Utils/Schema/MonitorSchemas.mjs +9 -0
  228. package/Utils/Schema/OpenApiMetadataRegistry.d.mts +4 -0
  229. package/Utils/Schema/OpenApiMetadataRegistry.d.ts +4 -0
  230. package/Utils/Schema/OpenApiMetadataRegistry.js +20 -0
  231. package/Utils/Schema/OpenApiMetadataRegistry.mjs +2 -0
  232. package/Utils/Schema/TypeSchemas.d.mts +12 -0
  233. package/Utils/Schema/TypeSchemas.d.ts +12 -0
  234. package/Utils/Schema/TypeSchemas.js +176 -0
  235. package/Utils/Schema/TypeSchemas.mjs +11 -0
  236. package/Utils/Schema/Zod.js +23 -17
  237. package/Utils/SecurityCase/SecurityCaseMarkdown.d.mts +34 -0
  238. package/Utils/SecurityCase/SecurityCaseMarkdown.d.ts +34 -0
  239. package/Utils/SecurityCase/SecurityCaseMarkdown.js +69 -0
  240. package/Utils/SecurityCase/SecurityCaseMarkdown.mjs +9 -0
  241. package/Utils/SecurityCase/SecurityCasePriorities.d.mts +2 -0
  242. package/Utils/SecurityCase/SecurityCasePriorities.d.ts +2 -0
  243. package/Utils/SecurityCase/SecurityCasePriorities.js +15 -1
  244. package/Utils/SecurityCase/SecurityCaseTargets.d.mts +128 -0
  245. package/Utils/SecurityCase/SecurityCaseTargets.d.ts +128 -0
  246. package/Utils/SecurityCase/SecurityCaseTargets.js +482 -0
  247. package/Utils/SecurityCase/SecurityCaseTargets.mjs +28 -0
  248. package/Utils/SecurityEvent/Sigma/SigmaRuleParser.js +22 -0
  249. package/Utils/SecurityEvent/Sigma/SigmaWatchlists.d.mts +24 -0
  250. package/Utils/SecurityEvent/Sigma/SigmaWatchlists.d.ts +24 -0
  251. package/Utils/SecurityEvent/Sigma/SigmaWatchlists.js +183 -0
  252. package/Utils/SecurityEvent/Sigma/SigmaWatchlists.mjs +9 -0
  253. package/package.json +1 -1
@@ -7,6 +7,7 @@ exports.readText = readText;
7
7
  exports.toOtelMacAddress = toOtelMacAddress;
8
8
  exports.isIpAddressLiteral = isIpAddressLiteral;
9
9
  exports.getNetworkDeviceEffectiveInputs = getNetworkDeviceEffectiveInputs;
10
+ exports.getRoleOfControllerProductType = getRoleOfControllerProductType;
10
11
  exports.getNetworkDeviceFactDetails = getNetworkDeviceFactDetails;
11
12
  exports.getNetworkDeviceHostname = getNetworkDeviceHostname;
12
13
  exports.getNetworkDeviceDnsName = getNetworkDeviceDnsName;
@@ -17,6 +18,7 @@ exports.getNetworkDeviceLocation = getNetworkDeviceLocation;
17
18
  exports.getNetworkDeviceSystemDescription = getNetworkDeviceSystemDescription;
18
19
  exports.getNetworkDeviceAssetFacts = getNetworkDeviceAssetFacts;
19
20
  const SnmpVendorTemplate_1 = __importDefault(require("../../Types/Monitor/SnmpMonitor/SnmpVendorTemplate"));
21
+ const NetworkControllerProvider_1 = require("../../Types/NetworkController/NetworkControllerProvider");
20
22
  const DeviceNameSource_1 = require("../../Types/NetworkDevice/DeviceNameSource");
21
23
  const NetworkDeviceDiscoveredDetails_1 = require("../../Types/NetworkDevice/NetworkDeviceDiscoveredDetails");
22
24
  const IP_1 = __importDefault(require("../../Types/IP/IP"));
@@ -109,6 +111,49 @@ function readTime(value) {
109
111
  function isSameValue(left, right) {
110
112
  return left.trim().toLowerCase() === right.trim().toLowerCase();
111
113
  }
114
+ /*
115
+ * One value of the device's controller reading, with its source - or nothing
116
+ * when the controller says nothing about it.
117
+ */
118
+ function controllerInput(reading, field) {
119
+ const value = reading === null || reading === void 0 ? void 0 : reading.values[field];
120
+ return reading && value
121
+ ? { value: value, source: (0, AssetFactSource_1.sourceOfControllerReading)(reading) }
122
+ : {};
123
+ }
124
+ /*
125
+ * A column a poll writes (or a person saved), with what the device's
126
+ * controller says about the same detail - its model, serial number,
127
+ * firmware, maker. The controller FILLS IN:
128
+ *
129
+ * - nothing else has a value: the controller's;
130
+ * - a value saved on the device: the saved value, which is never replaced,
131
+ * and the controller's beside it when the two differ;
132
+ * - a value the device's own poll read: the poll's. It is what the box
133
+ * says about itself, and both are read every few minutes - "the newer
134
+ * wins" between the two would hand the detail back and forth with every
135
+ * read wherever they spell it differently ("15.2(7)E" on the box,
136
+ * "switch-15-21" in the dashboard). A Meraki device's own poll reads no
137
+ * model, serial number or firmware, so for it the dashboard gives them.
138
+ */
139
+ function withControllerReading(input, controller) {
140
+ var _a;
141
+ if (!controller.value || !controller.source) {
142
+ return input;
143
+ }
144
+ if (!input.value) {
145
+ return controller;
146
+ }
147
+ if (((_a = input.source) === null || _a === void 0 ? void 0 : _a.kind) === AssetFactSource_1.AssetFactSourceKind.Saved &&
148
+ !input.discoveredDifferent &&
149
+ !isSameValue(input.value, controller.value)) {
150
+ return Object.assign(Object.assign({}, input), { discoveredDifferent: {
151
+ value: controller.value,
152
+ source: controller.source,
153
+ } });
154
+ }
155
+ return input;
156
+ }
112
157
  function differenceOf(entry) {
113
158
  return { value: entry.value, source: (0, AssetFactSource_1.sourceOfDiscoveredValue)(entry) };
114
159
  }
@@ -166,6 +211,7 @@ function readDiscoveredOnly(discovered) {
166
211
  * what discovery read - see the header for which wins.
167
212
  */
168
213
  function getNetworkDeviceEffectiveInputs(device) {
214
+ var _a;
169
215
  const details = (0, NetworkDeviceDiscoveredDetails_1.readNetworkDeviceDiscoveredDetails)(device.discoveredDetails);
170
216
  const lastPolledAt = readTime(device.lastSnmpSeenAt);
171
217
  const lastPolledAtIso = lastPolledAt === undefined
@@ -220,21 +266,58 @@ function getNetworkDeviceEffectiveInputs(device) {
220
266
  };
221
267
  }
222
268
  }
269
+ /*
270
+ * What the device's controller says (the Meraki dashboard): its maker
271
+ * is the controller's own, and its model, serial number and firmware are
272
+ * the box's. A controller reads no SNMP system group, so it fills none of
273
+ * those.
274
+ */
275
+ const controller = details.controller;
276
+ /*
277
+ * Its MAC, when nothing else gives one; and beside a typed one it differs
278
+ * from, when no ARP table already does.
279
+ */
280
+ const controllerMac = controllerInput(controller, NetworkDeviceDiscoveredDetails_1.NetworkDeviceControllerField.MacAddress);
281
+ if (controllerMac.value && controllerMac.source) {
282
+ if (!macAddress.value) {
283
+ macAddress = controllerMac;
284
+ }
285
+ else if (((_a = macAddress.source) === null || _a === void 0 ? void 0 : _a.kind) === AssetFactSource_1.AssetFactSourceKind.Saved &&
286
+ !macAddress.discoveredDifferent &&
287
+ ((0, EndpointAttachmentUtil_1.normalizeMac)(macAddress.value) || macAddress.value) !==
288
+ controllerMac.value) {
289
+ macAddress = Object.assign(Object.assign({}, macAddress), { discoveredDifferent: {
290
+ value: controllerMac.value,
291
+ source: controllerMac.source,
292
+ } });
293
+ }
294
+ }
295
+ const controllerMaker = controller
296
+ ? {
297
+ value: (0, NetworkControllerProvider_1.getNetworkControllerProviderTitle)(controller.provider),
298
+ source: (0, AssetFactSource_1.sourceOfControllerReading)(controller),
299
+ }
300
+ : {};
223
301
  return {
224
302
  sysName: polled(device.sysName, NetworkDeviceDiscoveredDetails_1.NetworkDeviceDiscoveredField.SystemName),
225
303
  sysDescr: polled(device.sysDescr, NetworkDeviceDiscoveredDetails_1.NetworkDeviceDiscoveredField.SystemDescription),
226
304
  sysObjectId: polled(device.sysObjectId, NetworkDeviceDiscoveredDetails_1.NetworkDeviceDiscoveredField.SystemObjectId),
227
305
  sysLocation: polled(device.sysLocation, NetworkDeviceDiscoveredDetails_1.NetworkDeviceDiscoveredField.SystemLocation),
228
306
  sysContact: polled(device.sysContact, NetworkDeviceDiscoveredDetails_1.NetworkDeviceDiscoveredField.SystemContact),
229
- vendor: polled(device.vendor),
230
- deviceModel: polled(device.deviceModel),
231
- serialNumber: polled(device.serialNumber),
232
- firmwareVersion: polled(device.firmwareVersion),
307
+ vendor: withControllerReading(polled(device.vendor), controllerMaker),
308
+ deviceModel: withControllerReading(polled(device.deviceModel), controllerInput(controller, NetworkDeviceDiscoveredDetails_1.NetworkDeviceControllerField.Model)),
309
+ serialNumber: withControllerReading(polled(device.serialNumber), controllerInput(controller, NetworkDeviceDiscoveredDetails_1.NetworkDeviceControllerField.SerialNumber)),
310
+ firmwareVersion: withControllerReading(polled(device.firmwareVersion), controllerInput(controller, NetworkDeviceDiscoveredDetails_1.NetworkDeviceControllerField.FirmwareVersion)),
233
311
  softwareVersion: polled(device.softwareVersion),
234
312
  dnsName: dnsName,
235
313
  macAddress: macAddress,
236
314
  netbiosName: readDiscoveredOnly(details.values[NetworkDeviceDiscoveredDetails_1.NetworkDeviceDiscoveredField.NetbiosName]),
237
315
  resolvedIpAddress: readDiscoveredOnly(details.values[NetworkDeviceDiscoveredDetails_1.NetworkDeviceDiscoveredField.IpAddress]),
316
+ controllerName: controllerInput(controller, NetworkDeviceDiscoveredDetails_1.NetworkDeviceControllerField.Name),
317
+ controllerIpAddress: controllerInput(controller, NetworkDeviceDiscoveredDetails_1.NetworkDeviceControllerField.IpAddress),
318
+ controllerMacAddress: controllerInput(controller, NetworkDeviceDiscoveredDetails_1.NetworkDeviceControllerField.MacAddress),
319
+ controllerAddress: controllerInput(controller, NetworkDeviceDiscoveredDetails_1.NetworkDeviceControllerField.Address),
320
+ controllerProductType: controllerInput(controller, NetworkDeviceDiscoveredDetails_1.NetworkDeviceControllerField.ProductType),
238
321
  details: details,
239
322
  };
240
323
  }
@@ -315,7 +398,12 @@ function getHostnameFact(device, inputs, dnsName) {
315
398
  dnsName: dnsNameForHostname.value,
316
399
  });
317
400
  if (!(choice === null || choice === void 0 ? void 0 : choice.name)) {
318
- return {};
401
+ /*
402
+ * Nothing the device says names it: the name its controller files it
403
+ * under (the Meraki dashboard's), when it has one. Still never its
404
+ * address.
405
+ */
406
+ return fact(inputs.controllerName.value, inputs.controllerName);
319
407
  }
320
408
  const from = choice.source === DeviceNameSource_1.DeviceNameSource.SystemName
321
409
  ? systemName
@@ -338,7 +426,11 @@ function getIpAddressFact(device, inputs) {
338
426
  * A device polled at a DNS name: the address its probe resolved the name
339
427
  * to - only ever recorded for that very name, so it is the device's.
340
428
  */
341
- return fact(inputs.resolvedIpAddress.value, inputs.resolvedIpAddress);
429
+ if (inputs.resolvedIpAddress.value) {
430
+ return fact(inputs.resolvedIpAddress.value, inputs.resolvedIpAddress);
431
+ }
432
+ // Else the management address its controller lists for it.
433
+ return fact(inputs.controllerIpAddress.value, inputs.controllerIpAddress);
342
434
  }
343
435
  function isSnmpAgentVendor(vendor) {
344
436
  return SNMP_AGENT_VENDORS.has(vendor.trim().toLowerCase());
@@ -394,7 +486,7 @@ function getDeviceTypeFact(device, inputs, options) {
394
486
  if (assignedName) {
395
487
  return fact(assignedName, { kind: AssetFactSource_1.AssetFactSourceKind.AssignedRole });
396
488
  }
397
- const classified = (0, NetworkDeviceRoleUtil_1.classifyDeviceRole)({
489
+ let classified = (0, NetworkDeviceRoleUtil_1.classifyDeviceRole)({
398
490
  sysDescr: inputs.sysDescr.value,
399
491
  sysObjectId: inputs.sysObjectId.value,
400
492
  vendor: inputs.vendor.value,
@@ -402,31 +494,59 @@ function getDeviceTypeFact(device, inputs, options) {
402
494
  name: readText(device.name),
403
495
  sysName: inputs.sysName.value || readText(device.hostname),
404
496
  });
497
+ let classifiedBy = { kind: AssetFactSource_1.AssetFactSourceKind.Classified };
498
+ /*
499
+ * Nothing it reports or is called says what it is: what its controller
500
+ * files it as (a Meraki "switch", "wireless"...), when it says.
501
+ */
502
+ const controllerRole = classified === "unknown"
503
+ ? getRoleOfControllerProductType(inputs.controllerProductType.value)
504
+ : undefined;
505
+ if (controllerRole && inputs.controllerProductType.source) {
506
+ classified = controllerRole;
507
+ classifiedBy = inputs.controllerProductType.source;
508
+ }
405
509
  const assignedKey = readText((_b = device.networkDeviceRole) === null || _b === void 0 ? void 0 : _b.key);
406
510
  const roleKey = (0, NetworkDeviceRoleCatalog_1.roleKeyForNode)(assignedKey, classified);
407
511
  const projectLabel = (0, NetworkDeviceRoleCatalog_1.stampForRoleKey)(roleKey, (0, NetworkDeviceRoleCatalog_1.buildDeviceRoleIndex)((options === null || options === void 0 ? void 0 : options.roles) || [])).roleLabel;
408
512
  if (projectLabel) {
409
- return fact(projectLabel, {
410
- kind: assignedKey
411
- ? AssetFactSource_1.AssetFactSourceKind.AssignedRole
412
- : AssetFactSource_1.AssetFactSourceKind.Classified,
413
- });
513
+ return fact(projectLabel, assignedKey ? { kind: AssetFactSource_1.AssetFactSourceKind.AssignedRole } : classifiedBy);
414
514
  }
415
515
  if (classified === "unknown") {
416
516
  return {};
417
517
  }
418
- return fact((0, NetworkDeviceRoleUtil_1.labelForDeviceRole)(classified), {
419
- kind: AssetFactSource_1.AssetFactSourceKind.Classified,
420
- });
518
+ return fact((0, NetworkDeviceRoleUtil_1.labelForDeviceRole)(classified), classifiedBy);
421
519
  }
422
520
  /*
423
- * Where the device says it is (sysLocation), or nothing for a blank or an
424
- * agent's default.
521
+ * The role a controller's product type stands for, or undefined for one that
522
+ * names no network role (a sensor, a Systems Manager endpoint). A Meraki MX
523
+ * or Z - an "appliance" - is a security appliance, as the classifier draws an
524
+ * MX; a cellular or campus gateway routes.
525
+ */
526
+ const ROLE_BY_CONTROLLER_PRODUCT_TYPE = {
527
+ appliance: "firewall",
528
+ switch: "switch",
529
+ wireless: "wirelessAccessPoint",
530
+ wirelessController: "wirelessAccessPoint",
531
+ camera: "camera",
532
+ cellularGateway: "router",
533
+ campusGateway: "router",
534
+ };
535
+ function getRoleOfControllerProductType(productType) {
536
+ if (!productType ||
537
+ !Object.prototype.hasOwnProperty.call(ROLE_BY_CONTROLLER_PRODUCT_TYPE, productType)) {
538
+ return undefined;
539
+ }
540
+ return ROLE_BY_CONTROLLER_PRODUCT_TYPE[productType];
541
+ }
542
+ /*
543
+ * Where the device says it is (sysLocation) - else the street address its
544
+ * controller files it under - or nothing for a blank or an agent's default.
425
545
  */
426
546
  function getSystemLocation(inputs) {
427
547
  const location = inputs.sysLocation.value;
428
548
  if (!location || PLACEHOLDER_LOCATIONS.has(location.toLowerCase())) {
429
- return {};
549
+ return fact(inputs.controllerAddress.value, inputs.controllerAddress);
430
550
  }
431
551
  return fact(location, inputs.sysLocation);
432
552
  }
@@ -482,6 +602,7 @@ function getNetworkDeviceFactDetails(device, options) {
482
602
  },
483
603
  foundBy: inputs.details.foundBy,
484
604
  otherMachine: inputs.details.otherMachine,
605
+ controller: inputs.details.controller,
485
606
  };
486
607
  }
487
608
  /**
@@ -10,6 +10,7 @@ export const getNetworkDeviceLocation = commonJsModule.getNetworkDeviceLocation;
10
10
  export const getNetworkDeviceManufacturer = commonJsModule.getNetworkDeviceManufacturer;
11
11
  export const getNetworkDeviceSystemDescription = commonJsModule.getNetworkDeviceSystemDescription;
12
12
  export const getNetworkDeviceType = commonJsModule.getNetworkDeviceType;
13
+ export const getRoleOfControllerProductType = commonJsModule.getRoleOfControllerProductType;
13
14
  export const isIpAddressLiteral = commonJsModule.isIpAddressLiteral;
14
15
  export const readText = commonJsModule.readText;
15
16
  export const toOtelMacAddress = commonJsModule.toOtelMacAddress;
@@ -0,0 +1,88 @@
1
+ import { NetworkDeviceControllerReading } from "../../Types/NetworkDevice/NetworkDeviceDiscoveredDetails.mjs";
2
+ export declare const NETWORK_DEVICE_REFRESH_PENDING_MS: number;
3
+ export declare const NETWORK_DEVICE_REFRESH_GIVE_UP_MS: number;
4
+ export declare const NETWORK_DEVICE_REFRESH_POLL_AT: Date;
5
+ export declare const MONITOR_BACKED_REASON: string;
6
+ export declare const NO_PROBE_REASON: string;
7
+ export declare const POLLING_OFF_REASON: string;
8
+ export declare const CONTROLLER_OFF_REASON: string;
9
+ export interface NetworkDeviceRefreshAnswer {
10
+ requestedAt: string;
11
+ isProbeReading: boolean;
12
+ probeName?: string | undefined;
13
+ isControllerReading: boolean;
14
+ controllerName?: string | undefined;
15
+ wasAlreadyRequested: boolean;
16
+ }
17
+ export declare function readNetworkDeviceRefreshAnswer(value: unknown): NetworkDeviceRefreshAnswer | undefined;
18
+ export interface NetworkDeviceRefreshSource {
19
+ probeId?: unknown;
20
+ isPollingEnabled?: unknown;
21
+ monitoringMethod?: unknown;
22
+ hostname?: unknown;
23
+ discoveredDetails?: unknown;
24
+ }
25
+ export interface NetworkDeviceRefreshReaders {
26
+ isProbePolled: boolean;
27
+ controller?: NetworkDeviceControllerReading | undefined;
28
+ }
29
+ /**
30
+ * Who can be asked to read a device again: its probe, its controller, both,
31
+ * or neither (then Refresh has nothing to ask, and is not offered).
32
+ */
33
+ export declare function getNetworkDeviceRefreshReaders(device: NetworkDeviceRefreshSource): NetworkDeviceRefreshReaders;
34
+ export declare function canRefreshNetworkDevice(device: NetworkDeviceRefreshSource): boolean;
35
+ /**
36
+ * True for a refresh asked for so recently, and not answered yet, that a new
37
+ * ask is the same one.
38
+ */
39
+ export declare function isNetworkDeviceRefreshPending(data: {
40
+ refreshRequestedAt: unknown;
41
+ lastPolledAt: unknown;
42
+ now: Date;
43
+ }): boolean;
44
+ /**
45
+ * True when a poll that lands now is the first since someone asked for the
46
+ * device to be read again: the poll before it landed before the ask.
47
+ */
48
+ export declare function isFirstPollSinceRefresh(data: {
49
+ refreshRequestedAt: unknown;
50
+ previousLastPolledAt: unknown;
51
+ }): boolean;
52
+ export declare enum NetworkDeviceRefreshProgress {
53
+ Waiting = "waiting",
54
+ Read = "read",
55
+ Unreachable = "unreachable",
56
+ Late = "late"
57
+ }
58
+ export interface NetworkDeviceRefreshStanding {
59
+ progress: NetworkDeviceRefreshProgress;
60
+ isProbePending: boolean;
61
+ isControllerPending: boolean;
62
+ }
63
+ /**
64
+ * Where a refresh stands, from the device as it reads now: its probe has
65
+ * answered once it polled the device after the ask (lastPolledAt), and its
66
+ * controller once its reading was read after the ask (the reading's
67
+ * readAt). Both on the server's clock, as the ask's time is; only "late"
68
+ * reads the page's own clock, and three minutes leave room for a skew.
69
+ */
70
+ export declare function getNetworkDeviceRefreshStanding(data: {
71
+ answer: NetworkDeviceRefreshAnswer;
72
+ lastPolledAt: unknown;
73
+ isReachable: unknown;
74
+ controllerReadAt: unknown;
75
+ now: Date;
76
+ }): NetworkDeviceRefreshStanding;
77
+ /**
78
+ * A refresh someone asked for that has not been answered yet, and is not
79
+ * late: what a page opened after the ask - another tab, a reload - shows as
80
+ * under way. Who reads it is worked out from the device as it is.
81
+ */
82
+ export declare function getPendingNetworkDeviceRefresh(data: {
83
+ device: NetworkDeviceRefreshSource & {
84
+ refreshRequestedAt?: unknown;
85
+ lastPolledAt?: unknown;
86
+ };
87
+ now: Date;
88
+ }): NetworkDeviceRefreshAnswer | undefined;
@@ -0,0 +1,88 @@
1
+ import { NetworkDeviceControllerReading } from "../../Types/NetworkDevice/NetworkDeviceDiscoveredDetails";
2
+ export declare const NETWORK_DEVICE_REFRESH_PENDING_MS: number;
3
+ export declare const NETWORK_DEVICE_REFRESH_GIVE_UP_MS: number;
4
+ export declare const NETWORK_DEVICE_REFRESH_POLL_AT: Date;
5
+ export declare const MONITOR_BACKED_REASON: string;
6
+ export declare const NO_PROBE_REASON: string;
7
+ export declare const POLLING_OFF_REASON: string;
8
+ export declare const CONTROLLER_OFF_REASON: string;
9
+ export interface NetworkDeviceRefreshAnswer {
10
+ requestedAt: string;
11
+ isProbeReading: boolean;
12
+ probeName?: string | undefined;
13
+ isControllerReading: boolean;
14
+ controllerName?: string | undefined;
15
+ wasAlreadyRequested: boolean;
16
+ }
17
+ export declare function readNetworkDeviceRefreshAnswer(value: unknown): NetworkDeviceRefreshAnswer | undefined;
18
+ export interface NetworkDeviceRefreshSource {
19
+ probeId?: unknown;
20
+ isPollingEnabled?: unknown;
21
+ monitoringMethod?: unknown;
22
+ hostname?: unknown;
23
+ discoveredDetails?: unknown;
24
+ }
25
+ export interface NetworkDeviceRefreshReaders {
26
+ isProbePolled: boolean;
27
+ controller?: NetworkDeviceControllerReading | undefined;
28
+ }
29
+ /**
30
+ * Who can be asked to read a device again: its probe, its controller, both,
31
+ * or neither (then Refresh has nothing to ask, and is not offered).
32
+ */
33
+ export declare function getNetworkDeviceRefreshReaders(device: NetworkDeviceRefreshSource): NetworkDeviceRefreshReaders;
34
+ export declare function canRefreshNetworkDevice(device: NetworkDeviceRefreshSource): boolean;
35
+ /**
36
+ * True for a refresh asked for so recently, and not answered yet, that a new
37
+ * ask is the same one.
38
+ */
39
+ export declare function isNetworkDeviceRefreshPending(data: {
40
+ refreshRequestedAt: unknown;
41
+ lastPolledAt: unknown;
42
+ now: Date;
43
+ }): boolean;
44
+ /**
45
+ * True when a poll that lands now is the first since someone asked for the
46
+ * device to be read again: the poll before it landed before the ask.
47
+ */
48
+ export declare function isFirstPollSinceRefresh(data: {
49
+ refreshRequestedAt: unknown;
50
+ previousLastPolledAt: unknown;
51
+ }): boolean;
52
+ export declare enum NetworkDeviceRefreshProgress {
53
+ Waiting = "waiting",
54
+ Read = "read",
55
+ Unreachable = "unreachable",
56
+ Late = "late"
57
+ }
58
+ export interface NetworkDeviceRefreshStanding {
59
+ progress: NetworkDeviceRefreshProgress;
60
+ isProbePending: boolean;
61
+ isControllerPending: boolean;
62
+ }
63
+ /**
64
+ * Where a refresh stands, from the device as it reads now: its probe has
65
+ * answered once it polled the device after the ask (lastPolledAt), and its
66
+ * controller once its reading was read after the ask (the reading's
67
+ * readAt). Both on the server's clock, as the ask's time is; only "late"
68
+ * reads the page's own clock, and three minutes leave room for a skew.
69
+ */
70
+ export declare function getNetworkDeviceRefreshStanding(data: {
71
+ answer: NetworkDeviceRefreshAnswer;
72
+ lastPolledAt: unknown;
73
+ isReachable: unknown;
74
+ controllerReadAt: unknown;
75
+ now: Date;
76
+ }): NetworkDeviceRefreshStanding;
77
+ /**
78
+ * A refresh someone asked for that has not been answered yet, and is not
79
+ * late: what a page opened after the ask - another tab, a reload - shows as
80
+ * under way. Who reads it is worked out from the device as it is.
81
+ */
82
+ export declare function getPendingNetworkDeviceRefresh(data: {
83
+ device: NetworkDeviceRefreshSource & {
84
+ refreshRequestedAt?: unknown;
85
+ lastPolledAt?: unknown;
86
+ };
87
+ now: Date;
88
+ }): NetworkDeviceRefreshAnswer | undefined;
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NetworkDeviceRefreshProgress = exports.CONTROLLER_OFF_REASON = exports.POLLING_OFF_REASON = exports.NO_PROBE_REASON = exports.MONITOR_BACKED_REASON = exports.NETWORK_DEVICE_REFRESH_POLL_AT = exports.NETWORK_DEVICE_REFRESH_GIVE_UP_MS = exports.NETWORK_DEVICE_REFRESH_PENDING_MS = void 0;
4
+ exports.readNetworkDeviceRefreshAnswer = readNetworkDeviceRefreshAnswer;
5
+ exports.getNetworkDeviceRefreshReaders = getNetworkDeviceRefreshReaders;
6
+ exports.canRefreshNetworkDevice = canRefreshNetworkDevice;
7
+ exports.isNetworkDeviceRefreshPending = isNetworkDeviceRefreshPending;
8
+ exports.isFirstPollSinceRefresh = isFirstPollSinceRefresh;
9
+ exports.getNetworkDeviceRefreshStanding = getNetworkDeviceRefreshStanding;
10
+ exports.getPendingNetworkDeviceRefresh = getPendingNetworkDeviceRefresh;
11
+ const NetworkDeviceMonitoringMethod_1 = require("../../Types/NetworkDevice/NetworkDeviceMonitoringMethod");
12
+ const NetworkDeviceDiscoveredDetails_1 = require("../../Types/NetworkDevice/NetworkDeviceDiscoveredDetails");
13
+ /*
14
+ * "REFRESH": READ A NETWORK DEVICE AGAIN NOW (OneUptime issue #5185: "Inventory
15
+ * should support refreshing discovered information as devices and network
16
+ * details change").
17
+ *
18
+ * A device's details are read on schedules: its probe polls it every few
19
+ * minutes, a network controller connection reads Meraki every few minutes,
20
+ * discovery scans sweep its address every few hours, and its Inventory item
21
+ * copies the device every fifteen minutes. After a firmware upgrade or a
22
+ * swapped box, a person should not have to wait for those: Refresh asks the
23
+ * readers that can be asked to read it now.
24
+ *
25
+ * - Its probe, when a probe polls it (polling on, a probe and an address,
26
+ * not monitor-backed): the device goes to the front of its probe's queue,
27
+ * so the probe's next fetch - within a minute - pings it, and walks it
28
+ * when it has SNMP credentials. Its Inventory item is copied as soon as
29
+ * that poll lands.
30
+ * - Its controller, when a network controller connection describes it
31
+ * (the Meraki dashboard): that connection is read at once, and writes
32
+ * the device's reading again even when nothing in it changed - so the
33
+ * reading says it was read just now.
34
+ *
35
+ * Discovery scans are not run from here: a scan sweeps a whole range, and
36
+ * sweeping a /16 to refresh one device is out of all proportion. What they
37
+ * read stays as it is, with when.
38
+ *
39
+ * Pure, and shared: the refresh route decides with it, the poll pipeline
40
+ * knows a poll answers a refresh with it, and the Dashboard draws the
41
+ * button's states with it.
42
+ */
43
+ /*
44
+ * A refresh asked for again within this long of the last one, before that
45
+ * one was answered, IS that one: nothing is queued twice.
46
+ */
47
+ exports.NETWORK_DEVICE_REFRESH_PENDING_MS = 60 * 1000;
48
+ /*
49
+ * How long a refresh is waited for. A probe fetches every minute; past this
50
+ * the probe is likely offline or busy, and the page says so.
51
+ */
52
+ exports.NETWORK_DEVICE_REFRESH_GIVE_UP_MS = 3 * 60 * 1000;
53
+ // Where a refreshed device goes in its probe's queue: first.
54
+ exports.NETWORK_DEVICE_REFRESH_POLL_AT = new Date(0);
55
+ /*
56
+ * Why a device cannot be read again now, as the refresh route refuses it
57
+ * and the card shows it (NetworkDeviceRefreshRunner.getCannotRefreshReason).
58
+ * The server's own words, as every refusal the API sends is.
59
+ */
60
+ exports.MONITOR_BACKED_REASON = "This device is checked by its monitor, so nothing polls it: there is nothing to read again. Its details come from discovery scans of its address.";
61
+ exports.NO_PROBE_REASON = "No probe polls this device yet. Pick the probe that reaches it in the device's Settings, then refresh it.";
62
+ exports.POLLING_OFF_REASON = "Polling is turned off for this device. Turn it on in the device's Settings to read it again.";
63
+ /*
64
+ * A device only its Meraki connection reads, while that connection is
65
+ * turned off: the card offered Refresh for the connection's reading, so the
66
+ * refusal names the connection rather than the probe the device never had.
67
+ */
68
+ exports.CONTROLLER_OFF_REASON = "The Meraki connection that reads this device is turned off. Turn it on at the foot of the network's Traffic page, then refresh the device.";
69
+ /*
70
+ * An answer read back without trusting its shape: undefined when it is not
71
+ * one (no time that parses, nobody reading).
72
+ */
73
+ function readNetworkDeviceRefreshAnswer(value) {
74
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
75
+ return undefined;
76
+ }
77
+ const answer = value;
78
+ const requestedAt = readTime(answer["requestedAt"]);
79
+ const isProbeReading = answer["isProbeReading"] === true;
80
+ const isControllerReading = answer["isControllerReading"] === true;
81
+ if (requestedAt === undefined || (!isProbeReading && !isControllerReading)) {
82
+ return undefined;
83
+ }
84
+ const text = (key) => {
85
+ const read = answer[key];
86
+ return typeof read === "string" && read.trim() ? read.trim() : undefined;
87
+ };
88
+ const probeName = text("probeName");
89
+ const controllerName = text("controllerName");
90
+ return Object.assign(Object.assign(Object.assign(Object.assign({ requestedAt: new Date(requestedAt).toISOString(), isProbeReading: isProbeReading }, (probeName ? { probeName: probeName } : {})), { isControllerReading: isControllerReading }), (controllerName ? { controllerName: controllerName } : {})), { wasAlreadyRequested: answer["wasAlreadyRequested"] === true });
91
+ }
92
+ function readTime(value) {
93
+ if (value instanceof Date) {
94
+ const time = value.getTime();
95
+ return Number.isNaN(time) ? undefined : time;
96
+ }
97
+ if (typeof value === "string" && value.trim()) {
98
+ const time = new Date(value.trim()).getTime();
99
+ return Number.isNaN(time) ? undefined : time;
100
+ }
101
+ return undefined;
102
+ }
103
+ /**
104
+ * Who can be asked to read a device again: its probe, its controller, both,
105
+ * or neither (then Refresh has nothing to ask, and is not offered).
106
+ */
107
+ function getNetworkDeviceRefreshReaders(device) {
108
+ const hostname = typeof device.hostname === "string" ? device.hostname.trim() : "";
109
+ const probeId = device.probeId === undefined || device.probeId === null
110
+ ? ""
111
+ : String(device.probeId).trim();
112
+ const monitoringMethod = typeof device.monitoringMethod === "string"
113
+ ? device.monitoringMethod
114
+ : undefined;
115
+ const isProbePolled = Boolean(probeId &&
116
+ hostname &&
117
+ device.isPollingEnabled !== false &&
118
+ NetworkDeviceMonitoringMethod_1.NetworkDeviceMonitoringMethodUtil.isProbePolled(monitoringMethod));
119
+ const controller = (0, NetworkDeviceDiscoveredDetails_1.readNetworkDeviceDiscoveredDetails)(device.discoveredDetails).controller;
120
+ return controller
121
+ ? { isProbePolled: isProbePolled, controller: controller }
122
+ : { isProbePolled: isProbePolled };
123
+ }
124
+ // True when something can be asked to read the device again.
125
+ function canRefreshNetworkDevice(device) {
126
+ const readers = getNetworkDeviceRefreshReaders(device);
127
+ return readers.isProbePolled || Boolean(readers.controller);
128
+ }
129
+ /**
130
+ * True for a refresh asked for so recently, and not answered yet, that a new
131
+ * ask is the same one.
132
+ */
133
+ function isNetworkDeviceRefreshPending(data) {
134
+ const requestedAt = readTime(data.refreshRequestedAt);
135
+ if (requestedAt === undefined) {
136
+ return false;
137
+ }
138
+ const polledAt = readTime(data.lastPolledAt);
139
+ const age = data.now.getTime() - requestedAt;
140
+ return (age >= 0 &&
141
+ age < exports.NETWORK_DEVICE_REFRESH_PENDING_MS &&
142
+ (polledAt === undefined || polledAt < requestedAt));
143
+ }
144
+ /**
145
+ * True when a poll that lands now is the first since someone asked for the
146
+ * device to be read again: the poll before it landed before the ask.
147
+ */
148
+ function isFirstPollSinceRefresh(data) {
149
+ const requestedAt = readTime(data.refreshRequestedAt);
150
+ if (requestedAt === undefined) {
151
+ return false;
152
+ }
153
+ const previous = readTime(data.previousLastPolledAt);
154
+ return previous === undefined || previous < requestedAt;
155
+ }
156
+ var NetworkDeviceRefreshProgress;
157
+ (function (NetworkDeviceRefreshProgress) {
158
+ // Asked, and waiting for the readers.
159
+ NetworkDeviceRefreshProgress["Waiting"] = "waiting";
160
+ // Every reader asked has read it since, and its probe reached it.
161
+ NetworkDeviceRefreshProgress["Read"] = "read";
162
+ // Its probe polled it since the ask, and could not reach it.
163
+ NetworkDeviceRefreshProgress["Unreachable"] = "unreachable";
164
+ // A reader asked has not read it in the time a read takes.
165
+ NetworkDeviceRefreshProgress["Late"] = "late";
166
+ })(NetworkDeviceRefreshProgress || (exports.NetworkDeviceRefreshProgress = NetworkDeviceRefreshProgress = {}));
167
+ /**
168
+ * Where a refresh stands, from the device as it reads now: its probe has
169
+ * answered once it polled the device after the ask (lastPolledAt), and its
170
+ * controller once its reading was read after the ask (the reading's
171
+ * readAt). Both on the server's clock, as the ask's time is; only "late"
172
+ * reads the page's own clock, and three minutes leave room for a skew.
173
+ */
174
+ function getNetworkDeviceRefreshStanding(data) {
175
+ const requestedAt = readTime(data.answer.requestedAt);
176
+ const polledAt = readTime(data.lastPolledAt);
177
+ const controllerReadAt = readTime(data.controllerReadAt);
178
+ const isAnsweredAt = (time) => {
179
+ return (requestedAt !== undefined && time !== undefined && time >= requestedAt);
180
+ };
181
+ const isProbePending = data.answer.isProbeReading && !isAnsweredAt(polledAt);
182
+ const isControllerPending = data.answer.isControllerReading && !isAnsweredAt(controllerReadAt);
183
+ if (!isProbePending && !isControllerPending) {
184
+ return {
185
+ progress: data.answer.isProbeReading && data.isReachable === false
186
+ ? NetworkDeviceRefreshProgress.Unreachable
187
+ : NetworkDeviceRefreshProgress.Read,
188
+ isProbePending: false,
189
+ isControllerPending: false,
190
+ };
191
+ }
192
+ const isLate = requestedAt !== undefined &&
193
+ data.now.getTime() - requestedAt >= exports.NETWORK_DEVICE_REFRESH_GIVE_UP_MS;
194
+ return {
195
+ progress: isLate
196
+ ? NetworkDeviceRefreshProgress.Late
197
+ : NetworkDeviceRefreshProgress.Waiting,
198
+ isProbePending: isProbePending,
199
+ isControllerPending: isControllerPending,
200
+ };
201
+ }
202
+ /**
203
+ * A refresh someone asked for that has not been answered yet, and is not
204
+ * late: what a page opened after the ask - another tab, a reload - shows as
205
+ * under way. Who reads it is worked out from the device as it is.
206
+ */
207
+ function getPendingNetworkDeviceRefresh(data) {
208
+ var _a;
209
+ const requestedAt = readTime(data.device.refreshRequestedAt);
210
+ if (requestedAt === undefined ||
211
+ data.now.getTime() - requestedAt >= exports.NETWORK_DEVICE_REFRESH_GIVE_UP_MS) {
212
+ return undefined;
213
+ }
214
+ const readers = getNetworkDeviceRefreshReaders(data.device);
215
+ const controllerReadAt = readTime((_a = readers.controller) === null || _a === void 0 ? void 0 : _a.readAt);
216
+ const answer = {
217
+ requestedAt: new Date(requestedAt).toISOString(),
218
+ isProbeReading: readers.isProbePolled,
219
+ isControllerReading: Boolean(readers.controller),
220
+ wasAlreadyRequested: true,
221
+ };
222
+ const standing = getNetworkDeviceRefreshStanding({
223
+ answer: answer,
224
+ lastPolledAt: data.device.lastPolledAt,
225
+ isReachable: undefined,
226
+ controllerReadAt: controllerReadAt,
227
+ now: data.now,
228
+ });
229
+ return standing.progress === NetworkDeviceRefreshProgress.Waiting
230
+ ? answer
231
+ : undefined;
232
+ }