@@ -7946,49 +7946,59 @@ def get_xmpprelays_list(self, session, start, limit, filter, presence):
7946
7946
'inventoried_online' : [],
7947
7947
'total_machines' : [],
7948
7948
}
7949
- if query is not None :
7950
- sql1 = """select count(id) as nb
7951
- from machines
7952
- where uuid_inventorymachine IS NULL and enabled = 0 and agenttype="machine" """
7953
- sql2 = """select count(id) as nb
7954
- from machines
7955
- where uuid_inventorymachine IS NULL and enabled = 1 and agenttype="machine"
7956
- """
7949
+ sql_counts = """SELECT
7950
+ SUM(1) AS total,
7951
+ SUM(CASE
7952
+ WHEN (uuid_inventorymachine IS NULL and enabled = 0) THEN 1
7953
+ ELSE 0
7954
+ END) AS `uninventoried_offline`,
7955
+ SUM(CASE
7956
+ WHEN (uuid_inventorymachine IS NULL and enabled = 1) THEN 1
7957
+ ELSE 0
7958
+ END) AS `uninventoried_online`,
7959
+
7960
+ SUM(CASE
7961
+ WHEN (uuid_inventorymachine IS NOT NULL and enabled = 0) THEN 1
7962
+ ELSE 0
7963
+ END) AS `inventoried_offline`,
7964
+ SUM(CASE
7965
+ WHEN (uuid_inventorymachine IS NOT NULL and enabled = 1) THEN 1
7966
+ ELSE 0
7967
+ END) AS `inventoried_online`,
7968
+ groupdeploy as jid
7969
+ from machines where agenttype="machine" group by groupdeploy;"""
7970
+
7971
+ counts_result = session .execute (sql_counts )
7972
+ #uninventoried_offline = [x for x in count_uninventoried_offline]
7973
+
7974
+ counts = [{
7975
+ "total" : int (count_ars [0 ]),
7976
+ "uninventoried_offline" : int (count_ars [1 ]),
7977
+ "uninventoried_online" : int (count_ars [2 ]),
7978
+ "inventoried_offline" : int (count_ars [3 ]),
7979
+ "inventoried_online" : int (count_ars [4 ]),
7980
+ "jid" : count_ars [5 ]
7981
+ } for count_ars in counts_result ]
7957
7982
7958
- sql3 = """select count(id) as nb
7959
- from machines
7960
- where uuid_inventorymachine IS NOT NULL and enabled = 0 and agenttype="machine"
7961
- """
7962
- sql4 = """select count(id) as nb
7963
- from machines
7964
- where uuid_inventorymachine IS NOT NULL and enabled = 1 and agenttype="machine"
7965
- """
7983
+ if query is not None :
7966
7984
for machine in query :
7967
- _sql1 = sql1 + """and groupdeploy = "%s";""" % machine .jid
7968
- count_uninventoried_offline = session .execute (_sql1 )
7969
- uninventoried_offline = [x for x in count_uninventoried_offline ]
7970
-
7971
- _sql2 = sql2 + """and groupdeploy = "%s";""" % machine .jid
7972
- count_uninventoried_offline = session .execute (_sql2 )
7973
- uninventoried_online = [x for x in count_uninventoried_offline ]
7974
-
7975
- _sql3 = sql3 + """and groupdeploy = "%s";""" % machine .jid
7976
- count_uninventoried_offline = session .execute (_sql3 )
7977
- inventoried_offline = [x for x in count_uninventoried_offline ]
7978
-
7979
- _sql4 = sql4 + """and groupdeploy = "%s";""" % machine .jid
7980
- count_uninventoried_offline = session .execute (_sql4 )
7981
- inventoried_online = [x for x in count_uninventoried_offline ]
7982
-
7983
- total_machines = uninventoried_offline [0 ][0 ] + \
7984
- uninventoried_online [0 ][0 ] + \
7985
- inventoried_offline [0 ][0 ] + \
7986
- inventoried_online [0 ][0 ]
7987
- result ['uninventoried_offline' ].append (uninventoried_offline [0 ][0 ])
7988
- result ['uninventoried_online' ].append (uninventoried_online [0 ][0 ])
7989
- result ['inventoried_offline' ].append (inventoried_offline [0 ][0 ])
7990
- result ['inventoried_online' ].append (inventoried_online [0 ][0 ])
7991
- result ['total_machines' ].append (total_machines )
7985
+ flag = False
7986
+ for count_ars in counts :
7987
+ if machine .jid == count_ars ["jid" ]:
7988
+ flag = True
7989
+ break
7990
+ if flag == True :
7991
+ result ['uninventoried_offline' ].append (count_ars ["uninventoried_offline" ])
7992
+ result ['uninventoried_online' ].append (count_ars ["uninventoried_online" ])
7993
+ result ['inventoried_offline' ].append (count_ars ["inventoried_offline" ])
7994
+ result ['inventoried_online' ].append (count_ars ["inventoried_online" ])
7995
+ result ['total_machines' ].append (count_ars ["total" ])
7996
+ else :
7997
+ result ['uninventoried_offline' ].append (0 )
7998
+ result ['uninventoried_online' ].append (0 )
7999
+ result ['inventoried_offline' ].append (0 )
8000
+ result ['inventoried_online' ].append (0 )
8001
+ result ['total_machines' ].append (0 )
7992
8002
7993
8003
result ['id' ].append (machine .id )
7994
8004
result ['jid' ].append (machine .jid )
0 commit comments