@@ -158,6 +158,187 @@ func (md *MongoDatabase) getHosts(mode string, filters dto.SearchHostsFilters, o
158158 model .TechnologyPostgreSQLPostgreSQL : "$features.postgresql.instances.name" ,
159159 model .TechnologyMongoDBMongoDB : "$features.mongodb.instances.name" ,
160160 },
161+ "technology" : bson.D {
162+ {Key : "$switch" ,
163+ Value : bson.D {
164+ {Key : "branches" ,
165+ Value : bson.A {
166+ bson.D {
167+ {Key : "case" ,
168+ Value : bson.D {
169+ {Key : "$or" ,
170+ Value : bson.A {
171+ bson.D {
172+ {Key : "$eq" ,
173+ Value : bson.A {
174+ bson.D {{Key : "$type" , Value : "$features.oracle" }},
175+ "object" ,
176+ },
177+ },
178+ },
179+ bson.D {
180+ {Key : "$and" ,
181+ Value : bson.A {
182+ bson.D {{Key : "$isArray" , Value : "$features.oracle.database.databases" }},
183+ bson.D {
184+ {Key : "$gt" ,
185+ Value : bson.A {
186+ bson.D {{Key : "$size" , Value : "$features.oracle.database.databases" }},
187+ 0 ,
188+ },
189+ },
190+ },
191+ },
192+ },
193+ },
194+ },
195+ },
196+ },
197+ },
198+ {Key : "then" , Value : model .TechnologyOracleDatabase },
199+ },
200+ bson.D {
201+ {Key : "case" ,
202+ Value : bson.D {
203+ {Key : "$or" ,
204+ Value : bson.A {
205+ bson.D {
206+ {Key : "$eq" ,
207+ Value : bson.A {
208+ bson.D {{Key : "$type" , Value : "$features.microsoft" }},
209+ "object" ,
210+ },
211+ },
212+ },
213+ bson.D {
214+ {Key : "$and" ,
215+ Value : bson.A {
216+ bson.D {{Key : "$isArray" , Value : "$features.microsoft.sqlServer.instances" }},
217+ bson.D {
218+ {Key : "$gt" ,
219+ Value : bson.A {
220+ bson.D {{Key : "$size" , Value : "$features.microsoft.sqlServer.instances" }},
221+ 0 ,
222+ },
223+ },
224+ },
225+ },
226+ },
227+ },
228+ },
229+ },
230+ },
231+ },
232+ {Key : "then" , Value : model .TechnologyMicrosoftSQLServer },
233+ },
234+ bson.D {
235+ {Key : "case" ,
236+ Value : bson.D {
237+ {Key : "$or" ,
238+ Value : bson.A {
239+ bson.D {
240+ {Key : "$eq" ,
241+ Value : bson.A {
242+ bson.D {{Key : "$type" , Value : "$features.mysql" }},
243+ "object" ,
244+ },
245+ },
246+ },
247+ bson.D {
248+ {Key : "$and" ,
249+ Value : bson.A {
250+ bson.D {{Key : "$isArray" , Value : "$features.mysql.instances" }},
251+ bson.D {
252+ {Key : "$gt" ,
253+ Value : bson.A {
254+ bson.D {{Key : "$size" , Value : "$features.mysql.instances" }},
255+ 0 ,
256+ },
257+ },
258+ },
259+ },
260+ },
261+ },
262+ },
263+ },
264+ },
265+ },
266+ {Key : "then" , Value : model .TechnologyOracleMySQL },
267+ },
268+ bson.D {
269+ {Key : "case" ,
270+ Value : bson.D {
271+ {Key : "$or" ,
272+ Value : bson.A {
273+ bson.D {
274+ {Key : "$eq" ,
275+ Value : bson.A {
276+ bson.D {{Key : "$type" , Value : "$features.postgresql" }},
277+ "object" ,
278+ },
279+ },
280+ },
281+ bson.D {
282+ {Key : "$and" ,
283+ Value : bson.A {
284+ bson.D {{Key : "$isArray" , Value : "$features.postgresql.instances" }},
285+ bson.D {
286+ {Key : "$gt" ,
287+ Value : bson.A {
288+ bson.D {{Key : "$size" , Value : "$features.postgresql.instances" }},
289+ 0 ,
290+ },
291+ },
292+ },
293+ },
294+ },
295+ },
296+ },
297+ },
298+ },
299+ },
300+ {Key : "then" , Value : model .TechnologyPostgreSQLPostgreSQL },
301+ },
302+ bson.D {
303+ {Key : "case" ,
304+ Value : bson.D {
305+ {Key : "$or" ,
306+ Value : bson.A {
307+ bson.D {
308+ {Key : "$eq" ,
309+ Value : bson.A {
310+ bson.D {{Key : "$type" , Value : "$features.mongodb" }},
311+ "object" ,
312+ },
313+ },
314+ },
315+ bson.D {
316+ {Key : "$and" ,
317+ Value : bson.A {
318+ bson.D {{Key : "$isArray" , Value : "$features.mongodb.instances" }},
319+ bson.D {
320+ {Key : "$gt" ,
321+ Value : bson.A {
322+ bson.D {{Key : "$size" , Value : "$features.mongodb.instances" }},
323+ 0 ,
324+ },
325+ },
326+ },
327+ },
328+ },
329+ },
330+ },
331+ },
332+ },
333+ },
334+ {Key : "then" , Value : model .TechnologyMongoDBMongoDB },
335+ },
336+ },
337+ },
338+ {Key : "default" , Value : primitive.Null {}},
339+ },
340+ },
341+ },
161342 })),
162343 mu .APOptionalStage (mode == "lms" , mu .MAPipeline (
163344 mu .APMatch (mu .QOExpr (mu .APOGreater (mu .APOSize ("$features.oracle.database.databases" ), 0 ))),
@@ -844,41 +1025,81 @@ func (md *MongoDatabase) ExistNotInClusterHost(hostname string) (bool, error) {
8441025}
8451026
8461027func (md * MongoDatabase ) getHostTechnology (hostname string , olderThan time.Time ) (string , error ) {
847- var result map [string ]float64 = make (map [string ]float64 )
1028+ var result map [string ]bool = make (map [string ]bool )
8481029
8491030 var out string
8501031
1032+ pipeline := bson.A {
1033+ bson.D {
1034+ {Key : "$match" ,
1035+ Value : bson.D {
1036+ {Key : "hostname" , Value : hostname },
1037+ {Key : "archived" , Value : false },
1038+ },
1039+ },
1040+ },
1041+ bson.D {
1042+ {Key : "$project" ,
1043+ Value : bson.D {
1044+ {Key : "Oracle/Database" ,
1045+ Value : bson.D {
1046+ {Key : "$eq" ,
1047+ Value : bson.A {
1048+ bson.D {{Key : "$type" , Value : "$features.oracle" }},
1049+ "object" ,
1050+ },
1051+ },
1052+ },
1053+ },
1054+ {Key : "Microsoft/SQLServer" ,
1055+ Value : bson.D {
1056+ {Key : "$eq" ,
1057+ Value : bson.A {
1058+ bson.D {{Key : "$type" , Value : "$features.microsoft" }},
1059+ "object" ,
1060+ },
1061+ },
1062+ },
1063+ },
1064+ {Key : "Oracle/MySQL" ,
1065+ Value : bson.D {
1066+ {Key : "$eq" ,
1067+ Value : bson.A {
1068+ bson.D {{Key : "$type" , Value : "$features.mysql" }},
1069+ "object" ,
1070+ },
1071+ },
1072+ },
1073+ },
1074+ {Key : "PostgreSQL/PostgreSQL" ,
1075+ Value : bson.D {
1076+ {Key : "$eq" ,
1077+ Value : bson.A {
1078+ bson.D {{Key : "$type" , Value : "$features.postgresql" }},
1079+ "object" ,
1080+ },
1081+ },
1082+ },
1083+ },
1084+ {Key : "MongoDB/MongoDB" ,
1085+ Value : bson.D {
1086+ {Key : "$eq" ,
1087+ Value : bson.A {
1088+ bson.D {{Key : "$type" , Value : "$features.mongodb" }},
1089+ "object" ,
1090+ },
1091+ },
1092+ },
1093+ },
1094+ },
1095+ },
1096+ },
1097+ bson.D {{Key : "$unset" , Value : "_id" }},
1098+ }
1099+
8511100 cur , err := md .Client .Database (md .Config .Mongodb .DBName ).Collection ("hosts" ).Aggregate (
8521101 context .TODO (),
853- mu .MAPipeline (
854- FilterByOldnessSteps (olderThan ),
855- mu .APMatch (bson.M {
856- "hostname" : hostname ,
857- }),
858- mu .APGroup (bson.M {
859- "_id" : 1 ,
860- model .TechnologyOracleDatabase : mu .APOSum (
861- mu .APOCond (mu .APOGreater (mu .APOSize (mu .APOIfNull ("$features.oracle.database.databases" , bson.A {})), 0 ), 1 , 0 ),
862- ),
863- model .TechnologyOracleExadata : mu .APOSum (
864- mu .APOCond (mu .APOGreater (mu .APOSize (mu .APOIfNull ("$features.oracle.exadata.components" , bson.A {})), 0 ), 1 , 0 ),
865- ),
866- model .TechnologyOracleMySQL : mu .APOSum (
867- mu .APOCond (mu .APOGreater (mu .APOSize (mu .APOIfNull ("$features.mysql.instances" , bson.A {})), 0 ), 1 , 0 ),
868- ),
869- model .TechnologyMicrosoftSQLServer : mu .APOSum (
870- mu .APOCond (mu .APOGreater (mu .APOSize (mu .APOIfNull ("$features.microsoft.sqlServer.instances" , bson.A {})), 0 ), 1 , 0 ),
871- ),
872- model .TechnologyPostgreSQLPostgreSQL : mu .APOSum (
873- mu .APOCond (mu .APOGreater (mu .APOSize (mu .APOIfNull ("$features.postgresql.instances" , bson.A {})), 0 ), 1 , 0 ),
874- ),
875- model .TechnologyMongoDBMongoDB : mu .APOSum (
876- mu .APOCond (mu .APOGreater (mu .APOSize (mu .APOIfNull ("$features.mongodb.instances" , bson.A {})), 0 ), 1 , 0 ),
877- ),
878- }),
879- mu .APUnset ("_id" ),
880- ),
881- )
1102+ pipeline )
8821103 if err != nil {
8831104 return "" , utils .NewError (err , "DB ERROR" )
8841105 }
@@ -892,8 +1113,8 @@ func (md *MongoDatabase) getHostTechnology(hostname string, olderThan time.Time)
8921113 return "" , utils .NewError (err , "DB ERROR" )
8931114 }
8941115
895- for technology , count := range result {
896- if count > 0 {
1116+ for technology , exist := range result {
1117+ if exist {
8971118 out = technology
8981119 break
8991120 }
0 commit comments