diff --git a/server/src/uds/core/util/stats/counters.py b/server/src/uds/core/util/stats/counters.py index 92a2bf610..3617cadee 100644 --- a/server/src/uds/core/util/stats/counters.py +++ b/server/src/uds/core/util/stats/counters.py @@ -25,6 +25,7 @@ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +from uds.models import NEVER ''' @author: Adolfo Gómez, dkmaster at dkmon dot com @@ -77,13 +78,14 @@ def getCounters(obj, counterType, **kwargs): to: (optional, defaults to 'Until end') En date for counter to recover limit: (optional, defaults to 1000) Number of counter to recover. This is an 'At most' advice. The returned number of value can be lower, or even 1 more than requested due to a division for retrieving object at database + all: (optinal), indicates that get all counters for the type of obj passed in, not only for that obj. Returns: A generator, that contains pairs of (stamp, value) tuples ''' - since = kwargs.get('since', None) - to = kwargs.get('to', None) + since = kwargs.get('since', NEVER) + to = kwargs.get('to', datetime.datetime.now()) limit = kwargs.get('limit', 1000) use_max = kwargs.get('use_max', False) @@ -100,7 +102,11 @@ def getCounters(obj, counterType, **kwargs): logger.error('Type {0} has no registerd stats of type {1}'.format(type(obj), counterType)) return - owner_ids = fnc(obj) + if kwargs.get('all', None) is not True: + owner_ids = fnc(obj) + else: + owner_ids = None + for i in statsManager().getCounters(__transDict[type(obj)], counterType, owner_ids, since, to, limit, use_max): val = (datetime.datetime.fromtimestamp(i.stamp), i.value) diff --git a/server/src/uds/models.py b/server/src/uds/models.py index e670aa459..17b1048ef 100644 --- a/server/src/uds/models.py +++ b/server/src/uds/models.py @@ -1626,7 +1626,7 @@ class StatsCounters(models.Model): filt += '='+str(owner_type) owner_id = None - if kwargs.has_key('owner_id'): + if kwargs.get('owner_id', None) is not None: filt += ' AND OWNER_ID' oid = kwargs['owner_id'] if type(oid) in (list, tuple): diff --git a/server/src/uds/xmlrpc/log/logs.py b/server/src/uds/xmlrpc/log/logs.py index 87555d035..5e310f644 100644 --- a/server/src/uds/xmlrpc/log/logs.py +++ b/server/src/uds/xmlrpc/log/logs.py @@ -36,6 +36,7 @@ from ..auths.AdminAuth import needs_credentials from ..util.Exceptions import FindException from uds.core.util import log +from uds.models import DeployedService from uds.models import UserService from uds.models import User from uds.models import Authenticator @@ -44,13 +45,23 @@ import logging logger = logging.getLogger(__name__) +@needs_credentials +def getDeployedServiceLogs(credentials, id): + try: + ds = DeployedService.objects.get(pk=id) + return log.getLogs(ds) + except: + logger.exception('Exception') + raise FindException(_('Deployed service does not exists')) + + @needs_credentials def getUserServiceLogs(credentials, id): try: us = UserService.objects.get(pk=id) return log.getLogs(us) except: - raise FindException(_('Service does not exists')) + raise FindException(_('User service does not exists')) @needs_credentials def getUserLogs(credentials, id): @@ -71,6 +82,7 @@ def getAuthLogs(credentials, id): # Registers XML RPC Methods def registerLogFunctions(dispatcher): + dispatcher.register_function(getDeployedServiceLogs, 'getDeployedServiceLogs') dispatcher.register_function(getUserServiceLogs, 'getUserServiceLogs') dispatcher.register_function(getUserLogs, 'getUserLogs') dispatcher.register_function(getAuthLogs, 'getAuthLogs') diff --git a/server/src/uds/xmlrpc/stats/stats.py b/server/src/uds/xmlrpc/stats/stats.py index 450c1eb3a..668d72275 100644 --- a/server/src/uds/xmlrpc/stats/stats.py +++ b/server/src/uds/xmlrpc/stats/stats.py @@ -53,9 +53,14 @@ def getDeployedServiceCounters(credentials, id, counter_type, since, to, points, val = cache.get(cacheKey) if val is None: - us = DeployedService.objects.get(pk=id) + if id == '-1': + us = DeployedService() + all = True + else: + us = DeployedService.objects.get(pk=id) + all = False val = [] - for x in counters.getCounters(us, counter_type, since=since, to=to, limit=points, use_max=use_max): + for x in counters.getCounters(us, counter_type, since=since, to=to, limit=points, use_max=use_max, all=all): val.append({ 'stamp': x[0], 'value': x[1] }) if len(val) > 2: cache.put(cacheKey, cPickle.dumps(val).encode('zip'), 3600)