per-agent configuration of batch processors, #71837
[freeside.git] / torrus / perllib / Torrus / SQL / SrvExport.pm
1 #  Copyright (C) 2005  Stanislav Sinyagin
2 #
3 #  This program is free software; you can redistribute it and/or modify
4 #  it under the terms of the GNU General Public License as published by
5 #  the Free Software Foundation; either version 2 of the License, or
6 #  (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software
15 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16
17 # $Id: SrvExport.pm,v 1.1 2010-12-27 00:03:59 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
19
20 # Class for Collector's external storage export data manipulation.
21
22 package Torrus::SQL::SrvExport;
23
24 use strict;
25
26 use Torrus::SQL;
27 use base 'Torrus::SQL';
28
29 use Torrus::Log;
30
31 # The name of the table and columns where the collector export is stored
32 # defaults configured in torrus-config.pl
33 our $tableName;
34 our %columns;
35
36 sub sqlInsertStatement
37 {
38     return sprintf('INSERT INTO %s (%s,%s,%s,%s,%s) VALUES (?,?,?,?,?)',
39                    $tableName,
40                    $columns{'srv_date'},
41                    $columns{'srv_time'},
42                    $columns{'serviceid'},
43                    $columns{'value'},
44                    $columns{'intvl'});
45 }
46                    
47
48 sub getServiceIDs
49 {
50     my $self = shift;
51     
52     $self->{'sql'}->select({
53         'fields' => [ $columns{'serviceid'} ],
54         'table' => $tableName,
55         'group' => [ $columns{'serviceid'} ],
56         'order' => [ $columns{'serviceid'} ] });
57
58     my $ret = [];
59     while( defined( my $row = $self->{'sql'}->fetchrow_arrayref() ) )
60     {
61         push( @{$ret}, $row->[0] );
62     }
63
64     return $ret;    
65 }    
66
67
68 # YYYY-MM-DD for start and end date
69 # returns the reference to the array of hashes for selected entries.
70
71 sub getIntervalData
72 {
73     my $self = shift;
74     my $startdate = shift;
75     my $enddate = shift;
76     my $serviceid = shift;
77
78     $self->{'sql'}->select({
79         'fields' =>
80             [ $columns{'srv_date'},
81               $columns{'srv_time'},
82               $columns{'value'},
83               $columns{'intvl'} ],
84             'table' => $tableName,
85             'where' => [ {$columns{'serviceid'} => $serviceid},
86                          'AND',
87                          {$columns{'srv_date'} => ['>=', $startdate]},
88                          'AND',
89                          {$columns{'srv_date'} => ['<', $enddate]}
90                          ]});
91
92     return $self->fetchall([ 'srv_date', 'srv_time', 'value', 'intvl' ]);
93 }
94
95
96     
97     
98     
99
100
101
102 1;
103
104
105 # Local Variables:
106 # mode: perl
107 # indent-tabs-mode: nil
108 # perl-indent-level: 4
109 # End: