set fixed values from an explicitly specified svcpart on replace too
[freeside.git] / FS / FS / nas.pm
1 package FS::nas;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw(qsearchs); #qsearch);
6 use FS::UID qw( dbh );
7
8 @ISA = qw(FS::Record);
9
10 =head1 NAME
11
12 FS::nas - Object methods for nas records
13
14 =head1 SYNOPSIS
15
16   use FS::nas;
17
18   $record = new FS::nas \%hash;
19   $record = new FS::nas {
20     'nasnum'  => 1,
21     'nasip'   => '10.4.20.23',
22     'nasfqdn' => 'box1.brc.nv.us.example.net',
23   };
24
25   $error = $record->insert;
26
27   $error = $new_record->replace($old_record);
28
29   $error = $record->delete;
30
31   $error = $record->check;
32
33   $error = $record->heartbeat($timestamp);
34
35 =head1 DESCRIPTION
36
37 An FS::nas object represents an Network Access Server on your network, such as
38 a terminal server or equivalent.  FS::nas inherits from FS::Record.  The
39 following fields are currently supported:
40
41 =over 4
42
43 =item nasnum - primary key
44
45 =item nas - NAS name
46
47 =item nasip - NAS ip address
48
49 =item nasfqdn - NAS fully-qualified domain name
50
51 =item last - timestamp indicating the last instant the NAS was in a known
52              state (used by the session monitoring).
53
54 =back
55
56 =head1 METHODS
57
58 =over 4
59
60 =item new HASHREF
61
62 Creates a new NAS.  To add the NAS to the database, see L<"insert">.
63
64 Note that this stores the hash reference, not a distinct copy of the hash it
65 points to.  You can ask the object for a copy with the I<hash> method.
66
67 =cut
68
69 # the new method can be inherited from FS::Record, if a table method is defined
70
71 sub table { 'nas'; }
72
73 =item insert
74
75 Adds this record to the database.  If there is an error, returns the error,
76 otherwise returns false.
77
78 =cut
79
80 # the insert method can be inherited from FS::Record
81
82 =item delete
83
84 Delete this record from the database.
85
86 =cut
87
88 # the delete method can be inherited from FS::Record
89
90 =item replace OLD_RECORD
91
92 Replaces the OLD_RECORD with this one in the database.  If there is an error,
93 returns the error, otherwise returns false.
94
95 =cut
96
97 # the replace method can be inherited from FS::Record
98
99 =item check
100
101 Checks all fields to make sure this is a valid example.  If there is
102 an error, returns the error, otherwise returns false.  Called by the insert
103 and replace methods.
104
105 =cut
106
107 # the check method should currently be supplied - FS::Record contains some
108 # data checking routines
109
110 sub check {
111   my $self = shift;
112
113   $self->ut_numbern('nasnum')
114     || $self->ut_text('nas')
115     || $self->ut_ip('nasip')
116     || $self->ut_domain('nasfqdn')
117     || $self->ut_numbern('last')
118     || $self->SUPER::check
119     ;
120 }
121
122 =item heartbeat TIMESTAMP
123
124 Updates the timestamp for this nas
125
126 =cut
127
128 sub heartbeat {
129   my($self, $timestamp) = @_;
130   my $dbh = dbh;
131   my $sth =
132     $dbh->prepare("UPDATE nas SET last = ? WHERE nasnum = ? AND last < ?");
133   $sth->execute($timestamp, $self->nasnum, $timestamp) or die $sth->errstr;
134   $self->last($timestamp);
135 }
136
137 =back
138
139 =head1 VERSION
140
141 $Id: nas.pm,v 1.7 2003-08-05 00:20:43 khoff Exp $
142
143 =head1 BUGS
144
145 heartbeat method uses SQL directly and doesn't update history tables.
146
147 =head1 SEE ALSO
148
149 L<FS::Record>, schema.html from the base documentation.
150
151 =cut
152
153 1;
154