Skip to content

Commit

Permalink
added set_rrd and get_rrd methods to generic_item and json server
Browse files Browse the repository at this point in the history
  • Loading branch information
hplato committed Feb 17, 2021
1 parent 4baca2c commit ae909e7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
44 changes: 44 additions & 0 deletions lib/Generic_Item.pm
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ sub new {
if ( defined $main::config_parms{object_logger_enable} );
$self->{logger_mintime} = 1;
$self->{logger_updatetime} = 0;
$self->{rrdfile} = undef; #if an rrdfile is attached to the object, then it can be displayed in the ia7 interface
$self->restore_data( 'active_state', 'schedule_count' );

for my $index ( 1 .. 20 ) {
Expand Down Expand Up @@ -1167,6 +1168,49 @@ sub logger {
$self->{logger_updatetime} = $tickcount;
}

=item C<set_rrd()>
Attach a rrd filename, and data source (ds) names to the object. Used to display a graph in the IA7 interface
=cut

sub set_rrd {
my ( $self, $rrdfile, $ds) = @_;

$self->{rrdfile} = $rrdfile;
$self->{rrdds} = $ds;

}

=item C<get_rrd()>
Get the rrd filename attached to the object.
=cut

sub get_rrd {
my ( $self) = @_;

return $self->{rrdfile};

}

=item C<get_rrd()>
Get the rrd datasources attached to the object.
=cut

sub get_rrd_ds {
my ( $self) = @_;

return $self->{rrdds};

}


=item C<reset_states2()>
TODO
Expand Down
14 changes: 11 additions & 3 deletions lib/json_server.pl
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ sub json_get {
$rrd_file = $config_parms{weather_data_rrd}
if ( ( defined $config_parms{weather_data_rrd} ) and ($config_parms{weather_data_rrd}));
my $rrd_source = "";
$rrd_file = $args{file}[0] if (defined $args{file}[0]);
$rrd_source = $args{source}[0] if (defined $args{source}[0]);
$rrd_file = $config_parms{"rrd_source_" . $rrd_source} if (defined $config_parms{"rrd_source_" . $rrd_source} and $config_parms{"rrd_source_" . $rrd_source});
$path = $config_parms{"rrd_source_" .$rrd_source . "_path"} if (defined $config_parms{"rrd_source_" . $rrd_source . "_path"} and $config_parms{"rrd_source_" . $rrd_source . "_path"});
Expand Down Expand Up @@ -1529,7 +1530,7 @@ sub json_object_detail {
my %json_complete_object;
my @f = qw( category filename measurement rf_id set_by members
state states state_log type label sort_order groups hidden parents schedule logger_status
idle_time text html seconds_remaining fp_location fp_icons fp_icon_set img link level rgb);
idle_time text html seconds_remaining fp_location fp_icons fp_icon_set img link level rgb rrd);

# Build list of fields based on those requested.
foreach my $f ( sort @f ) {
Expand All @@ -1539,6 +1540,7 @@ sub json_object_detail {

my $value;
my $method = $f;

if (
$object->can($method)
or ( ( $method = 'get_' . $method )
Expand Down Expand Up @@ -1571,6 +1573,13 @@ sub json_object_detail {

$value = $a if ( defined $a and $a ne "" ); #don't return a null value
}

elsif ( $f eq 'rrd' ) {
my $a = $object->$method;
$a = (split( /\/|\\/, $a))[-1]; #just take the filename
my $b = $object->get_rrd_ds();
$value = $a . ":" . $b if ( defined $a and $a ne "" ); #don't return a null value
}

elsif ( $f eq 'rgb' ) {
my ($a,$b,$c) = $object->$method;
Expand All @@ -1595,8 +1604,7 @@ sub json_object_detail {
$value = encode_entities( $value, '<>&"');

}
print_log "json: object_dets f $f m $method v $value"
if $Debug{json};
print_log "json: object_dets f $f m $method v $value" if $Debug{json};
}
elsif ( $f eq 'members' ) {
## Currently only list members for group items, but at some point we
Expand Down

0 comments on commit ae909e7

Please sign in to comment.