Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for case where field in fetch but not config #1553

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions lib/Munin/Master/UpdateWorker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,19 @@ sub _db_state_update {
WHERE ds.name = ?");
$sth_ds->execute($node_id, $plugin, $field);
my ($ds_id) = $sth_ds->fetchrow_array();
DEBUG "_db_state_update.ds_id:$ds_id";
DEBUG "_db_state_update.ds_id:" . ($ds_id || 'undef');
WARN "ds_id($plugin, $field, $when, $value) is NULL, SELECT ds.id FROM ds
JOIN service s ON ds.service_id = s.id AND s.node_id = '$node_id' AND s.name = '$plugin'
WHERE ds.name = '$field'" unless $ds_id;
$sth_ds->finish();

# Don't insert missing ds values
# Note, this means unconfigured ds values are lost, rather than
# kept with some default ds_attr values
if (!defined($ds_id)) {
return $ds_id;
}

# Update the state with the new values
my $sth_state_u = $dbh->prepare_cached("UPDATE state SET prev_epoch = last_epoch, prev_value = last_value, last_epoch = ?, last_value = ? WHERE id = ? AND type = ?");
my $rows_u = $sth_state_u->execute($when, $value, $ds_id, "ds");
Expand Down Expand Up @@ -756,10 +763,10 @@ sub uw_handle_fetch {

# Update all data-driven components: State, RRD, Graphite
my $ds_id = $self->_db_state_update($plugin, $field, $when, $value);
DEBUG "[DEBUG] ds_id($plugin, $field, $when, $value) = $ds_id";
DEBUG "[DEBUG] ds_id($plugin, $field, $when, $value) = " . ($ds_id || 'undef');

my ($rrd_file, $rrd_field);
{
if ($ds_id) {
# XXX - Quite inefficient, but works
my $dbh = $self->{dbh};
my $sth_rrdinfos = $dbh->prepare_cached(
Expand All @@ -774,6 +781,23 @@ sub uw_handle_fetch {
$rrd_field = $row[1] if $row[0] eq "rrd:field";
}
$sth_rrdinfos->finish();
} else {
# We have an unconfigured fetch value, make sure
# to store the data

# Need to have the service attrs, currently just for
# a potential update_rate value.
my $dbh = $self->{dbh};
my $sth_service_attrs = $dbh->prepare_cached("SELECT service_attr.name, service_attr.value FROM service_attr, service WHERE service.name=? and service.node_id=? and service.id = service_attr.id");
$sth_service_attrs->execute($plugin, $self->{node_id});
my %temp_ds_config = ( );
while (my ($_name, $_value) = $sth_service_attrs->fetchrow_array()) {
$temp_ds_config{$_name} = $_value;
}

my $first_epoch = time - (12 * 3600);
$rrd_file = $self->_create_rrd_file_if_needed($plugin, $field, \%temp_ds_config, $first_epoch);
$rrd_field = '42';
}

# This is a little convoluted but is needed as the API permits
Expand Down